06-29-2012 08:21 AM
Hi Guys,
How can i convert Qbytearray to image ,so that i can show in imageView.Any sample codes will be useful
Regards
Rakesh Shankar.P
Solved! Go to Solution.
07-01-2012 08:57 AM - edited 07-01-2012 09:18 AM
QImage has a constructor that takes a "uchar* data". I suppose the buffer is storred in QByteArray, so try to use the data in the byte array to construct a QImage using the appropriate constructor. If your QImage is valid, it is simple from now on:
QImage swapped = originalImageFromBuffer.rgbSwapped(); PixelBufferData pbd(RGBX /* or RGBA_PRE, depends on the buffer format*/, swapped.width(), swapped.height(), swapped.width(), (void*)swapped.constBits()); myImageView->setImage(pbd);
07-03-2012 11:25 AM
You're in good hands with AleksDef.
Read the full chain of thought at http://supportforums.blackberry.com/t5/Cascades-De
Stuart
07-04-2012 10:27 AM
Hi,
Still i am unable to retreive the images from server.Code that i used is
void HelloCascadesApp::finishedSlot(QNetworkReply* reply)
{
//printf (" %d ","In finishes slot");
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QByteArray data = reply->readAll();
uchar* imageChar = (uchar*)data.data();
QImage swapped(imageChar,200,150,QImage::Format_RGB32);
// PixelBufferData pbd(PixelBufferData::RGBX, swapped.width(), swapped.height(), swapped.width(), (void*)swapped.constBits());
PixelBufferData pbd(PixelBufferData::RGBX, swapped.width(), swapped.height(), swapped.width(), swapped.rgbSwapped().bits());
ImageView *testImage = new ImageView();
// Image imageAsset = Image(QUrl("asset:///images/bubble.png"));
Image image(pbd);
testImage->setImage(image);
container->add(testImage);
qDebug() << "Status :" << statusCode;
// imageView->setImage(temp);
}
besides there is another question of printing in console,i tried using Qdebug of Qt,but i am not able to getting anything in console,and there is anything in cascades to show pop up?
Regards
Rakesh Shankar.P
07-04-2012 11:08 AM - edited 07-04-2012 11:20 AM
First of all, never use this:
PixelBufferData pbd(PixelBufferData::RGBX, swapped.width(), swapped.height(), swapped.width(), swapped.rgbSwapped().bits());
This part: swapped.rgbSwapped().bits() caused issues (at least for me, because from my experience, swapped.width() was somehow not equal to swapped.rgbSwapped().width()).
What you need to do is store image.rgbSwapped() in a separate variable:
QImage swapped = imageCreatedFromData.rgbSwapped();
Then use:
PixelBufferData pbd(PixelBufferData::RGBX, swapped.width(), swapped.height(), swapped.width(), (void*)swapped.constBits());
It may look like a waste of space, but it is actually a workaround (was for me).
So your code should be like this:
//printf (" %d ","In finishes slot");
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAt tribute).toInt();
QByteArray data = reply->readAll();
uchar* imageChar = (uchar*)data.data();
QImage originalImage(imageChar,200,150,QImage::Format_RGB 32);
QImage swapped = originalImage.rgbSwapped();
PixelBufferData pbd(PixelBufferData::RGBX, swapped.width(), swapped.height(), swapped.width(), (void*)swapped.constBits());
ImageView *testImage = new ImageView();
Image image(pbd);
testImage->setImage(image);
container->add(testImage);
qDebug() << "Status :" << statusCode;The qDebug() call probably isn't reached because the application freezes if you use the code you used previously.
So, try this modified code. If this doesn't work, then check for image.isNull(). Maybe try to export the image somewhere and see if it is valid. If it is valid, there is no reason this modified code not to work.
07-05-2012 02:20 AM
Qdebug is not working in any class,i tried giving qdebug in constructor ,but still am not gettting anything in console.and i am getting the error as segmention fault in the line
QImage swapped = originalImage.rgbSwapped();
I tried checking orginalImage.isNull()..i am getting as false,which shows image is not null.But still i am not able to figure the reason for this error.
Regards
Rakesh Shankar.P
07-05-2012 07:26 AM - edited 07-05-2012 07:30 AM
A segmentation fault is something else entirely since it is generated by QImage directly. I can't help you much with that. However, maybe try exporting or drawing the image somewhere to see if it is really ok, maybe this will shed some light onto your problem.
Perhaps smacmartin can provide insigth with the segfault or with qDebug. Regarding the latter, have you tried doing:
printf("message to output");
fflush(stdout);
07-05-2012 08:09 AM
Hi,
Thanks for inputs .
When i use image of large size like http://www.standrews.k12.nf.ca/Computerwebquest/Co
Similarly for debugging in console ,Console gets blank while app is getting debugged,Is there configuration change for eclipse that needs to be done?
One more qn,regarding making networking call,i use signals and slots for making the image request call,Is there anyway apart from it?I am not fully aware any other APIs.
Regards
Rakesh Shankar.P
07-05-2012 08:39 AM - edited 07-05-2012 08:41 AM
The only case I've read a segmentation fault can happen by image editing on BB is if the image is larger than 2000x2000. However, I'm guessing that if you hardcode image dimensions in QImage's constructor, and the buffer you are using is actually bigger than the dimensions, then you might get a segfault. Similarly, if the buffer is smaller than the given width and height, perhaps this might cause black (empty) areas in the generated QImage. Not really sure on this, though.
For debugging I've always used printf with fflush or qDebug in QNX Momentics. This has always worked with Project > Run As. I don't know what happenes with Project > Debug As, never could've gotten that to work.
I don't know about the last question, maybe this is what you are looking for: https://developer.blackberry.com/cascades/referenc
07-05-2012 09:40 AM - edited 07-05-2012 09:42 AM
Thanks for your help ,i am was able to retreive image
QImage swapped; qDebug()<<"data"<<data.length(); swapped.loadFromData(data,0); qDebug()<<"swapped"<<swapped.width(); QImage assignedImage = swapped.rgbSwapped(); PixelBufferData pbd(PixelBufferData::RGBX, assignedImage.width(), assignedImage.height(), assignedImage.width(), (void*)assignedImage.constBits());
ImageView *testImage = new ImageView();
Image image(pbd);
testImage->setImage(image);
container->add(testImage);
Regards
Rakesh Shankar.P