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

Sunday, February 27th 2005, 10:53am

How to convert QImage to QByteArray and uchar* and then make a QMovie?

Hi, all,

I want to make a QMovie using a series of QImages. My method for creating a QMovie is as follows:

1. I firstly contrust a QMovie using "QMovie::QMovie ( QByteArray data, int bufsize = 1024 )" with one frame of QImage.

2. Then I add other frames into the QMovie using " void QMovie::pushData ( const uchar * data, int length )" frame by frame (each frame of QImage needs to be converted to uchar*).

Does this mechanism work for creating a QMovie? If it works, then my problems are:

How to convert a QImage to QByteArray and uchar*?

Thanks a lot.

Joye

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

2

Sunday, February 27th 2005, 10:59am

RE: How to convert QImage to QByteArray and uchar* and then make a QMovie?

Quoted

bool QImage::save ( QIODevice * device, const char * format, int quality = -1 ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
This function writes a QImage to the QIODevice, device. This can be used, for example, to save an image directly into a QByteArray:

Source code

1
2
3
4
5
    QImage image;
    QByteArray ba;
    QBuffer buffer( ba );
    buffer.open( IO_WriteOnly );
    image.save( &buffer, "PNG" ); // writes image into ba in PNG format


I doubt this will work though :) You should have a correct file format:

Quoted

The supported formats are MNG (if Qt is configured with MNG support enabled) and GIF (if Qt is configured with GIF support enabled, see qgif.h).

3

Sunday, February 27th 2005, 1:53pm

RE: How to convert QImage to QByteArray and uchar* and then make a QMovie?

Thank you very much for your reply.

As you pointed out, how to set up a correct file format for a movie? I can run Movie Qt example with format of MNG. And another problem is how to convert QImage to uchar*?

Thanks a lot!

Joye

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

4

Sunday, February 27th 2005, 2:25pm

RE: How to convert QImage to QByteArray and uchar* and then make a QMovie?

Quoted

Originally posted by mygerm
As you pointed out, how to set up a correct file format for a movie? I can run Movie Qt example with format of MNG.

Well... You need to have a MNG or GIF anim probably :)

Quoted


And another problem is how to convert QImage to uchar*?


QByteArray inherits QMemArray<char> which has a data() member and you already know how to convert an image to byte array. You can probably use it.

5

Sunday, February 27th 2005, 3:52pm

RE: How to convert QImage to QByteArray and uchar* and then make a QMovie?

Thank you very much for your reply.

Quoted

Originally posted by wysota

Quoted

Originally posted by mygerm
As you pointed out, how to set up a correct file format for a movie? I can run Movie Qt example with format of MNG.

Well... You need to have a MNG or GIF anim probably :)

This means that I should have an anim file in advance with MNG or GIF format. I just need to pushData into the movie file. Is this right?

Quoted


And another problem is how to convert QImage to uchar*?


QByteArray inherits QMemArray<char> which has a data() member and you already know how to convert an image to byte array. You can probably use it.


I understand this now.

6

Sunday, February 27th 2005, 3:53pm

RE: How to convert QImage to QByteArray and uchar* and then make a QMovie?

Thank you very much for your reply.

Quoted

Originally posted by wysota

Quoted

Originally posted by mygerm
As you pointed out, how to set up a correct file format for a movie? I can run Movie Qt example with format of MNG.

Well... You need to have a MNG or GIF anim probably :)


This means that I should have an anim file in advance with MNG or GIF format. I just need to pushData into the movie file. Is this right?

Quoted


And another problem is how to convert QImage to uchar*?


QByteArray inherits QMemArray<char> which has a data() member and you already know how to convert an image to byte array. You can probably use it.[/quote]

I understand this now.

hatulflezet

Professional

Posts: 1,301

Location: Munich Germany

Occupation: Programmer

  • Send private message

7

Sunday, February 27th 2005, 4:07pm

I had to deal with this subject my self, you might find this helpfull:
http://www.qtforum.org/thread.php?threadid=4493&sid=
Click here! I dare ya'!! :]
Project Archimedes
----------------------------------------------------------
"Don't panic, and thanks for all the fish!"

8

Sunday, February 27th 2005, 8:27pm

Quoted

Originally posted by hatulflezet
I had to deal with this subject my self, you might find this helpfull:
http://www.qtforum.org/thread.php?threadid=4493&sid=

Thanks a lot for your information.
I just read your post. My problem is that I need to create a movie from a series of QImages created in the program? This is different from your case. Would you give me any further suggestions for relizing this function?

Thanks!

Joye