You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, May 31st 2005, 11:59pm

display jpeg's

I have a unsigned char buffer that holds a jpeg image
and I don't know how to convert it.
I tried it with a bmp like this: (it almost works), but how can I
handle a jpeg!?

QImage img(320, 240, 32, 0);

unsigned idx = 0;
for (unsigned i = 0; i < 240; ++i) {
QRgb *line = (QRgb*)img.scanLine(i);

for (unsigned j = 0; j < 320; ++j) {
line[j] = qRgb(buffer[idx], buffer[idx + 1], buffer[idx + 2]);
idx += 3; // for RGBA += 4
}
}

bitBlt(this,0,0,&img);

Krasu

Intermediate

  • "Krasu" is male

Posts: 234

Location: Republic of Belarus

  • Send private message

2

Wednesday, June 1st 2005, 4:45am

RE: display jpeg's

Quoted


bool QImage::loadFromData ( const uchar * buf, uint len, const char * format = 0 )

Loads an image from the first len bytes of binary data in buf. Returns TRUE if the image was successfully loaded; otherwise returns FALSE.

If format is specified, the loader attempts to read the image using the specified format. If format is not specified (which is the default), the loader reads a few bytes from the header to guess the file format.

The QImageIO documentation lists the supported image formats and explains how to add extra formats.

This post has been edited 1 times, last edit by "Krasu" (Jun 1st 2005, 4:47am)