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
Developer
Posts: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA
Accepted Solution

QImage to Image conversion

Hi, I have a QImage that I wish to use in an ImageView. What I did was converted it into a bb::ImageData and then create a Image  using that ImageData. The code is given below.

 

QImage imageQ;
imageQ.load("app/native/assets/images/bg.png");
imageData = bb::ImageData::fromPixels(imageQ.bits(), bb::PixelFormat::RGBX, canvasWidth, canvasHeight, imageQ.bytesPerLine());

image = ImageView::create().
image(Image(imageData));

 

But the problem is that the image looks inverted. The original image and the image when converting from QImage to Image are at this public DropBox folder.

 

https://www.dropbox.com/sh/0c1tlan6a1jh0pv/AACDHIvqWTryXA0JjOo0_P-oa

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

Re: QImage to Image conversion

Try doing a

 

    imageQ = imageQ.rgbSwapped();

 before the fromPixels line.


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: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: QImage to Image conversion

That works. Also, if we have to save it as an image, we have to swapRGB again. Also, the color of the pen might have to be swapped too..