PDA

View Full Version : Read QImage into QMovie



yagabey
25th December 2014, 22:17
Hi,

I need to read a QImage data into QMovie. QImage may contain a gif, png or jpg file.. If i use filepath instead of QImage:

movie->setFileName("path")

everything goes well. I couldnt figure out how to do that for QImage. In the following code "state" returns true but "Movie->isValid()" returns false:


QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
bool state= image->save(&buffer,"PNG");
Movie = new QMovie(&buffer);

Any idea?

Thanks in advance...

anda_skoa
25th December 2014, 22:45
Maybe because your buffer is opened in WriteOnly mode.

Cheers,
_

yagabey
26th December 2014, 08:56
Hi, the result is same with ReadWrite mode...

anda_skoa
26th December 2014, 10:49
Have you tried specifying the format?
Have you tried resetting the buffer's position to the beginning?
Is there anything you actually tried yourself?

Cheers,
_

yagabey
26th December 2014, 12:47
Hmm, yeah. I think i tried everything that i could think :) . No way...


QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
buffer.seek(0);
bool state= image->save(&buffer,"PNG");
Movie = new QMovie(&buffer,"PNG");

wysota
26th December 2014, 13:26
Does it work if you save the image to a file and then you load the movie from that file?

anda_skoa
27th December 2014, 12:01
Hmm, yeah. I think i tried everything that i could think :) . No way...


QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
buffer.seek(0);
bool state= image->save(&buffer,"PNG");
Movie = new QMovie(&buffer,"PNG");

seek() before save() makes no sense, the buffer is at 0 because it is empty.

If you find it difficult to place the seek() after the save, try closing the buffer and re-opening it in read mode.

Cheers,
_