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
Accepted Solution

Create a QImage from bb::cascades::Image

Hi, how do we create a QImage from bb::cascades::Image or bb::cascades::ImageData?

 

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: Create a QImage from bb::cascades::Image

Do you need the extra step or are you happy to just load directly from source?

 

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

 


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: Create a QImage from bb::cascades::Image

I need that extra step, since I created the BB::cascades::Image from a third party library which returns a bb::cascades::image datatype.

Any thoughts?

Thank you
jayvdiyk.com
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Create a QImage from bb::cascades::Image

[ Edited ]

Hi!

I don't know how to extract ImageData from Image. But if you have access to ImageData, it has format() and pixels() methods which give access to raw image data.

 

QImage can load BMP files, so it should be possible to prepend the bitmap header to that data and feed it into QImage:

QImage image = QImage::fromData(data, "BMP");

There's a sample project by @slashkyle which shows how to append BMP header to raw screenshot data -

 

https://github.com/slashkyle/Cascades-Samples/blob/master/CaptureThis/src/applicationui.cpp

 

I didn't investigate if the image data should be additionally transformed or is in the proper format as is.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 82
Registered: ‎11-04-2011
My Device: PlayBook, DAC, SQN100-3, STL100-1, STL100-2
My Carrier: MTS RUS

Re: Create a QImage from bb::cascades::Image

Sorry for bring this dead thead to life, but you can easily extract data from bb::ImageData by using bb::utility::ImageConverter :

 

bb::ImageData imageData; // our source imageData
QByteArray
encoded = bb::utility::ImageConverter::encode("image/bmp", imageData);
QImage image; // destination QImage

if
(image.loadFromData(encoded, "BMP")) { // load QImage from encoded QByteArray as BMP stream
QImage scaledImage = image.scaled(720, 720, Qt::KeepAspectRatio); // if we wish to scale source image
scaledImage.save("sample.png", "PNG"); // if we wish to save scaled image
}