PDA

View Full Version : Image processing with using QByteArray



loading...
19th January 2015, 09:52
Hi all.
i have to process image in Qt, and i want do it with using qbytearray. I know how to convert QPixmap to QByteArray. For example:
QPixmap pixmap = OriginalImg.copy(0,0,x,y);
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");

PNG is a compressed format, so if the size of pixmap is 860x860, the size of ba is only 128518 (not 860*860*4). And i don't know how to change the color of pixel(i,j) on image using qbytearray ba. Can anyone teach me how to achieve it.
thanks:)

yeye_olive
19th January 2015, 10:52
You have seen for yourself that it is impractical to manipulate an image via through a serialized representation (here, PNG). Then why did you chose this route? Qt provides the QImage class to conveniently access pixels invidually, or even the plain binary data (QImage::​bits()). You can load a file into a QImage directly or, if all you have is a QPixmap, call QPixmap::​toImage().