2

I am new to StackOverFlow and wish there are experts to my problem, which consumed me a week time!

I embedded my JPEG files into a single data file, and need to load them on demand to avoid memory problem in mobile phone.

I wrote something like:

char *imageBuffer = getBytes(sourceFilename, offset, length);

to get a JPEG file data from a sourceFile with offset and length. I saved the bytes to file and it works.

My problem is how can I construct a QImage from the (char *) data? I tried many methods and haven't any success.

Wishing that there is experienced members to solve my problem. Thanks!!!

musefan
  • 47,875
  • 21
  • 135
  • 185
xuxiang
  • 45
  • 1
  • 6

1 Answers1

2

Yes, you can load using QImage::loadFromData().

cbuchart
  • 10,847
  • 9
  • 53
  • 93
Luca Carlon
  • 9,546
  • 13
  • 59
  • 91
  • Hi Luca, your reply really increased my confidence. In fact I tried the method before and failed many times. After your reply, I reviewed my code throughly and found that I loaded too many images in another routine and so the loadFromData call failed. It was so hard because I can only test the program on a Symbian XpressMusic phone and today only found that if I created more than about 6 QImages from JPEG, it will termainate with no reason! – xuxiang Nov 27 '11 at 14:56
  • Yes, it might fail for memory problems or when format cannot be determined reading the header data. You might want to try to embed using Qt resource file as a double check. – Luca Carlon Nov 27 '11 at 15:09