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
Posts: 29
Registered: ‎09-07-2012
My Device: 9900
My Carrier: Airtel

How to get the byte array from image in blackberry 10 cascades ?

[ Edited ]

Can any one help me for getting the byte array from image path in blackberry 10 cascades?

Developer
Posts: 84
Registered: ‎12-01-2012
My Device: 9790
My Carrier: Orange

Re: How to get the byte array from image in blackberry 10 cascades ?

It can be done with QFile. You need to open the file in binary mode.
Lublin BlackBerry Developer Group


---
If I helped you please mark my response as solution or "Like" it.
Contributor
Posts: 29
Registered: ‎09-07-2012
My Device: 9900
My Carrier: Airtel

Re: How to get the byte array from image in blackberry 10 cascades ?

Can you give some code for that?

 

I have tried the following but it will display the empty data only.

QFile file(QDir::currentPath()+filepath);
file.open(QIODevice::ReadOnly);
QByteArray data = file.readAll();  //Here the data is empty

 

 

 

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

Re: How to get the byte array from image in blackberry 10 cascades ?

Seems correct. Try printing the resulting filepath with qDebug() and check the return value of file.open() to ensure the file was successfully opened.

Andrey Fidrya, @zmeyc on twitter
Highlighted
Contributor
Posts: 29
Registered: ‎09-07-2012
My Device: 9900
My Carrier: Airtel

Re: How to get the byte array from image in blackberry 10 cascades ?

I have changed the image path and now am getting the bytes array like this ÿØÿà. 

 

MyCode

 

QFile file(QDir::currentPath() + "/app/native/assets/Icon/img.png");
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "error in  open the image path";
return;
}
else
{
 qDebug()<< QString(file.readAll());  //Here am getting  this symbol ÿØÿà
}

 

 

 

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: How to get the byte array from image in blackberry 10 cascades ?

In normal Qt (not Cascades) this works with transfering image over network socket (taken from here). 

 

QImage image;        // See the documentation on how to use QImage objects
image.load("test.png", "PNG");

QByteArray ba;              // Construct a QByteArray object
QBuffer buffer(&ba);        // Construct a QBuffer object using the QbyteArray
image.save(&buffer, "PNG"); // Save the QImage data into the QBuffer
//do whatever you want with the buffer