Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Combine 2 ImageData

Hi, how do we combine 2 ImageData into one Image?

 

I have 2 ImageData, I would like to place one ImageData on top of another.

 

Any thoughts? Thanks you

jayvdiyk.com
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Combine 2 ImageData

Have a look at QImage and QPainter use together you can merge the two images and produce one.

 

Alternatively if you are fairly okay with graphics and formats then you could combine them yourself using the Image::fromPixels() function.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Combine 2 ImageData

Could you post a snippet for Image::fromPixels() please?

In my case, it isn't possible to use a QImage..

Thank you..
jayvdiyk.com
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Combine 2 ImageData

Not knowing your images and what you are trying to do, not really, are you using transparancy or is the one on top a map of some sort (i.e. shader, bump, etc)?

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Combine 2 ImageData

You've got several threads on this open and it's a tad confusing, I asked in another whether you needed the extra step of loading an asset in to the Image if not then there are other approaches.

 

Why can't you use QImage?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Combine 2 ImageData

Sorry about that,

I am using skia to create a "text watermark" on the fly.

After that it resulted in a SkBitmap datatype. I am using RIM's class that convert an SkBitmap object to bb::cascades::ImageData. (I am using this class because I don't know how to convert an SkBitmap object)

I need to merge this watermark ImageData with another Image that I load from the device.

I can load this image and store it as a QImage or Image or ImageData object, but then the problem is that I need to put a generated watermark on top of it. This watermark object is an ImageData object.

Any thoughts?
jayvdiyk.com
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Combine 2 ImageData

Sorry I'm not familiar with the Skia library however I'd be very surprised if it didn't have a class or function that could do this for you, have you pursued doing it this way?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 188
Registered: ‎04-07-2013
My Device: BlackBerry Z10
My Carrier: Telus

Re: Combine 2 ImageData

[ Edited ]

Hi, Skia is a Open Source for many platforms library, I doubt that the guy behind would create a function to do this specifically for Qt..

I am placing my hope to the BlackBerry guy (smacmartin) who created the class to convert to ImageData. Just PM-ed him, Hope he could help providing a function to convert it to QImage.

Here is the class that he created a year ago

 

/*
 * PixelBuffer.cpp
 *
 *  Created on: Jul 9, 2012
 *      Author: smacmartin
 *  Revised on: Sept 4, 2012
 *     Author:  ling zhong
 */

#include "PixelBuffer.h"

using bb::ImageData;

PixelBuffer::PixelBuffer()
: m_sizeInPixels(0,0)
, m_buffer(0)
{
}

PixelBuffer::~PixelBuffer()
{
    deleteBuffer();
}

void PixelBuffer::deleteBuffer()
{
    if (m_buffer != 0)
    {
        delete [] m_buffer;
        m_buffer = 0;
    }
}



PixelBuffer& PixelBuffer::operator=(const SkBitmap& bitmap)
 {
	int w = bitmap.width();
	int h = bitmap.height();
	int numPixels = w * h;
	int numBytes = w * h * 4;

	QSize newImageSize(w, h);

	if (newImageSize != m_sizeInPixels) {
		deleteBuffer();
		m_sizeInPixels = QSize(w, h);
		m_buffer = new uchar[numBytes];
	}

	void* from = bitmap.getPixels();
	int numFromBytes = bitmap.getSize();
	int numToCopy = std::min(numFromBytes, numBytes);

	 memcpy(m_buffer, from, numToCopy);

	 if (numToCopy < numBytes)
	 {
		 memset(m_buffer + numToCopy, 0x00, numBytes - numToCopy);
	 }

	 for(unsigned int i=0; (i+4)<numToCopy; i=i+4)
	 {

		 uint *p= (uint*)(m_buffer+i);
		 uint *q= (uint*)(m_buffer+i);
*q = ((*p << 16) & 0xff0000) | ((*p >> 16) & 0xff) | (*p & 0xff00ff00); } return *this; } bb::ImageData PixelBuffer::getBuffer() const { return ImageData&colon;:fromPixels(m_buffer, bb::PixelFormat::RGBA_Premultiplied, m_sizeInPixels.width(), m_sizeInPixels.height(), m_sizeInPixels.width()*4); }

 

jayvdiyk.com
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Combine 2 ImageData

If you can't do the above then you would need to do something like...

 

QString appFolder(QDir::homePath());
appFolder.chop(4);
QString bg = appFolder + "app/native/assets/images/image.png";
QImage imgBG(bg);

 I notice that the skia bitmap class has a getPixels function it would then be a case of either using QPainter or QImage::setPixel() function to merge the images.

 

Not knowing the format of a skia bitmap you may need to convert using one of the conversion functions beforehand (e.g. rgbSwapped).

 

That's as far as I can go really as I've no desire to deep dive in to the skia library, hopefully one of these suggestions will help.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Combine 2 ImageData

[ Edited ]

Yes something along those lines is what I was suggesting however replacing the getPixels() function with the skia Bitmap class same function.

 

[edit] you misunderstood me about merging the images in my first suggestion. I was suggesting to do the whole thing using the skia library, load the image in to a skia bitmap not an ImageView then create your watermark within skia and merge within skia, only then converting it to an imageview.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.