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
Contributor
aaronmotek
Posts: 14
Registered: ‎10-04-2010
My Device: Not Specified
Accepted Solution

ImageView - cascades noob question

Please bare with me, as I'm new to QT & Cascades and trying to learn by hacking up a small app..

 

The Dev Alpha is missing a photo viewer, so it seemed like an obvious candidate for a first app.

 

I've managed to read the filesystem, and list all the images from the Camera directory, however.. I'm having trouble displaying any large camera images as an ImageView (small, non-camera images/screenshots display fine).  The debugger shows this error in the console:

 

"ERR: Image '/sdcard/DCIM/Camera/IMG_00000001.jpg' texture size 1836x3264 exceeds GL implementation max 2048"

 

This was created via:

 

   ImageView *image = ImageView::create("'/sdcard/DCIM/Camera/IMG_00000001.jpg").preferredSize(300,300);

 

The 300x300 preferred size doesn't seem to help - i'm assuming that's a post-scale after the image is already copied into memory.  Is there a recommended way to pre-scale the Image before passing it into ImageView, or another recommended way to handle this type of situation?

 

Thanks for your help.

 

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: ImageView - cascades noob question

Hello,

 

There is a limit to the dimensions of the pictures which can be handled by this call : 2048. For pictures above this, you can do the following...

 

Quoting one of the experts:

You can load up the image manually from the file into a QImage (http://qt-project.org/doc/qt-4.8/QImage.html), and then resize the image before setting the pixel buffers to set on the ImageView (https://bdsc.webapps.blackberry.com/cascades/reference/bb__cascades__ImageView.html).
 

QImage previewImage;
if(previewImage.load("filename")){
    //Scale to fill the screen to allow peek preview
    previewImage.scaled(size,Qt::KeepAspectRatio);
    QByteArray previewImageByteArray((const char*)previewImage.bits(), imageSize);
}


"
Feel free to ask for more clarifications/help.

Please use plain text.
Contributor
aaronmotek
Posts: 14
Registered: ‎10-04-2010
My Device: Not Specified

Re: ImageView - cascades noob question

[ Edited ]

Thanks Rashid!, I was heading down a similar path with QPixmap, not knowing which qt classes to use.  I saw the opportunity to create an Image from a bitmap, but wasn't sure how to get it to bitmap format to begin with.  Thanks!

 

The only disadvantage of this way I can see is that there's no easy way to hand it off to ImageView in qml.  If I do a QPixmap.load(origPath); QPixmap.scaleToHeight(screenHeight,Qt:: SmoothTransformation); QPixmal.save(cachedPath), and pass the cache path to the List instead, than we can keep it separate (but it will mean creating/managing a bunch of temp files in  our appdata directory).  I'm working with our designer on this as a proof of concept with the separation between qml/cpp, so we may still try this.

 

I think I'll start with your method and then go from there.  We'll stick it up on github if anybody's interested in the progression.  Thanks for getting back to us.

 

--aaron

Please use plain text.
Contributor
AleksDef
Posts: 42
Registered: ‎05-30-2012
My Device: Simulator
My Carrier: Developer

Re: ImageView - cascades noob question

Excuse me for the interuption, but can you tell me how to exactly set the data in QImage as the data source in ImageView? This is really not explained well in the Cascades documentation.

Please use plain text.
BlackBerry Development Advisor (Retired)
s_rashid
Posts: 127
Registered: ‎02-27-2012
My Device: Bold
My Carrier: Rogers

Re: ImageView - cascades noob question

 

Hello,

 

If you are simply trying to convert a "QImage" type to a Cascades "ImageView" type, you can do the following:

-------

 

 

PixelBufferData pbd(PixelBufferData::RGBA_PRE,yourQImage.width(),yourQImage.height(),yourQImage.width(),yourQImage.bits());

yourImageView->setImage(pbd);

 

-------

 

Hope that helps.

Please use plain text.
Developer
dkonigs
Posts: 248
Registered: ‎07-25-2008
My Device: Bold 9900

Re: ImageView - cascades noob question

[ Edited ]

s_rashid wrote:

 

Hello,

 

If you are simply trying to convert a "QImage" type to a Cascades "ImageView" type, you can do the following:

-------

 

 

PixelBufferData pbd(PixelBufferData::RGBA_PRE,yourQImage.width(),yourQImage.height(),yourQImage.width(),yourQImage.bits());

yourImageView->setImage(pbd);

 

-------

 

Hope that helps.


Working though a related problem myself, I can say that this is almost correct.  The problem is that QImage's pixel formats aren't really compatible with PixelBufferData.  If you use the above code as-is, you may see a weird color shift in the output.

 

Thankfully, Qt does provide a function that can convert QImage's pixel data into something compatible with PixelBufferData (which I think is an OpenGL format).  The methid is QGLWidget::convertToGLFormat().  However, using this method by itself also seems to flip the image, so you also need to account for that.  The full version of the conversion code (that works for me) is:

 

    QImage convertedImage = QGLWidget::convertToGLFormat(image.mirrored());

    PixelBufferData pixelData(
            PixelBufferData::RGBA_PRE,
            image.width(),
            image.height(),
            image.width(),
            (void *)convertedImage.bits());
    imageView->setImage(pixelData);

 

Of course you'll also need to add "QT += opengl" to your project's .pro file for things to link properly, when using that API.

Please use plain text.
Developer
JCarty
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: ImageView - cascades noob question

[ Edited ]

With regards to the color issue, this does the job too:

 

image.rgbSwapped();

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Please use plain text.
Contributor
AleksDef
Posts: 42
Registered: ‎05-30-2012
My Device: Simulator
My Carrier: Developer

Re: ImageView - cascades noob question

I apologize for interrupting a closed question, but this discussion is the closest to the issue I have, since I posed it here before. I tried using:

 

PixelBufferData pbd(PixelBufferData::RGBA_PRE, orgPattern.width(), orgPattern.height(),  orgPattern.width(),  orgPattern.rgbSwapped().bits());
m_patternFrame->setImage(pbd);

 

The QImage orgPattern was read from memory, and it is certain that the file path exists and points to a valid image because I used the same as a source elsewhere. m_patternFrame is a pointer to ImageView.

 

Instead of an image set to the view, I got this error:

Context: Failed to find target node with id %d 906.

 

Some times the number is different. Now it is 563.

What does it mean, and how do I fix it?

Please use plain text.
Developer
contryboy
Posts: 68
Registered: ‎08-16-2012
My Device: BB10 Dev Alpha
My Carrier: NA

Re: ImageView - cascades noob question

Hi,

 

I was directed to this thread when I met the same problem. How ever, the thread is old, and some of the class does not exist, and I figured it out with the latest sdk, here is the source code may help someone has the same problem:

void HttpImageView::setImageContent(const QByteArray &content) {
	QImage qImage;
	qImage.loadFromData(content);

	if(qImage.width()>MAX_IMAGE_WIDT_HEIGHT || qImage.height()>MAX_IMAGE_WIDT_HEIGHT) {
		if(qImage.width()>qImage.height()) {
			qImage = qImage.scaledToWidth(MAX_IMAGE_WIDT_HEIGHT).rgbSwapped();
		} else {
			qImage = qImage.scaledToHeight(MAX_IMAGE_WIDT_HEIGHT).rgbSwapped();
		}
		ImageData imageData = ImageData::fromPixels(qImage.bits(), PixelFormat::RGBA_Premultiplied, qImage.width(), qImage.height(), qImage.bytesPerLine());
		imageView->setImage(Image(imageData));
	} else {
		imageView->setImage(Image(content));
	}

	this->imageActualWidth = qImage.width();
	this->imageActualHeight = qImage.height();
}

 

Please use plain text.
Developer
contryboy
Posts: 68
Registered: ‎08-16-2012
My Device: BB10 Dev Alpha
My Carrier: NA

Re: ImageView - cascades noob question

Hi Rashid,

 

Does the 2048 limit exists in the OS or SDK? Is this limit still there in the lastst SDK? This is quite troublesome in some cases, e.g. for a very long image that contains texts, after resing, it's not possible to read those texts... Is there already a tickets for this?

 

 

Thanks,

Dong

Please use plain text.