01-22-2013 05:20 AM
Did any one manage to change the image of ImageView using QImage that load and image that have transparent zone?
I loaded a transparent image (from png files) to QImage, and the pass it to ImageView using this function :
https://developer.blackberry.com/cascades/referenc
Solved! Go to Solution.
01-22-2013 06:00 AM
You can create a Cascades image.
https://developer.blackberry.com/cascades/referenc
For example you can create the Image from a QByteArray.
Image image(imageData);
You can also create the Image from ImageData but I have never done this.
You can either set the image to the ImageView in C++ with ImageView.setImage(). Or you can assign the Image in QML to the property ImageView.image.
01-22-2013 06:17 AM
01-22-2013 07:04 AM
If your image is on the file system then you can assign it directly to the ImageView.
ImageView {
imageSource: "asset:///images/image.png"
}
01-22-2013 08:38 AM
Do not do this conversion to ImageData. Your method can simply return a QImage. Then you can assign it in QML to the property ImageView.image.
01-22-2013 10:02 PM
01-23-2013 03:09 AM
You can also assign the image in C++. If your image is on the file system then you can set the image path of ImageView.
setImageSource(QUrl("asset:///images/image.png"));
01-23-2013 03:39 AM - edited 01-23-2013 04:15 AM
Probably you're reading image to QImage incorrectly. Right now I'm using this approach (not ideal way, but works):
//////////////////////////////////////////
//Read image to QImage
QFile file(imageFilePath);
QImageReader imgReader(&file);
QImage image;
imgReader.read(&image);
image.convertToFormat(QImage::Format_ARGB32_Premul
//Do anything with QImage pixel data 'image' (e.g. apply some effect)
//Set imageData
ImageData pixelBuffer = ImageData::fromPixels(image.rgbSwapped().bit
bb:: PixelFormat::RGBA_Premultiplied,
reader.width(),
reader.height(),
image.bytesPerLine());
Image bbimage = Image(pixelBuffer);
if (!bbimage.isNull()) {
myImageView->setImage(bbimage);
}
////////////////////////////////////
01-23-2013 03:52 AM
myImageView->setImageSource(QUrl(imageFilePath));
01-23-2013 04:16 AM
I would avoid this conversion to ImageData. You can also create an Image from a QByteArray.
QByteArray imgData = imgReader.device()->readAll(); Image img(imgData); myImageView.setImage(img);