PDA

View Full Version : QPixmap import/export



Matthias
31st May 2007, 13:54
Hello everybody,

i have a problem using the QPixmap class in Qt. I want to change QPixmaps in char* and vice versa because my framegrabber stores images in that way.

Example:
myClass::myMethod(QPixmap *myQPixmap)
{

// create imagepointer to image in framebuffer
mem0[0] = (char*) Fg_getImagePtrEx(fg,1,dma_no,pmem0);

// create test images in framebuffer, black to white gradient
for(int i=0;i<width*height;i++)
{
mem0[0][i] = i;}
}

In this method i want to use the given myQPixmap as source instead of the generated test image. How can i do that?

Many thanks,
Matthias

high_flyer
31st May 2007, 14:49
convert the QPixmap to QImage, and use QImage::bits() to access the raw data.
And PLEASE, use code tags, and not that hideous blue color.

Matthias
1st June 2007, 08:03
convert the QPixmap to QImage, and use QImage::bits() to access the raw data.
And PLEASE, use code tags, and not that hideous blue color.

Thank you, i converted the QPixmap to QImage and tried copy the Qimage to the raw data.


// my raw data
unsigned char *myField = (unsigned char*) Fg_getImagePtrEx(fg,1,dma_no,pmem0);

// converting QPixmap to QImage
QImage testImage = testPixmap->convertToImage ();

// fill the Field with data from QImage (I think there is an Error)
myField = testImage.bits();

Do i only copy one pixel? Whats wrong?

high_flyer
1st June 2007, 09:11
Do i only copy one pixel? Whats wrong?
you are doing it the other way around...
You said you want to

to change QPixmaps in char* and vice versa
Then:


unsigned char *myField = (unsigned char*) Fg_getImagePtrEx(fg,1,dma_no,pmem0);
//Pixmap to unsigned char*
QPixmap *pixmap = new QPixmap("image.png");
unsigned char *buff = pixmap->convertToImage().bits(); //access the raw image data
//unsigned char to Pixmap
pixmap->loadFromData(myField,imageSize);


Have a look at QPixmap and QImage.