QImage - Retrieve data from an 8 bit bitmap image
Hi,
I have an 8 bit bitmap image that I need to read, retrieve the data and use that information as the alpha channel for another image. How do I go about doing that? I have tried the below code, but doesn’t seem to work.
- // This detects and shows 3, which is QImage::Format_Indexed8. Fine so far.
- qDebug()<<"alpha image format " <<alpha.format();
- img2.setPixel(j,y,qRgba(red,gren,blue,cola.alpha()));
Any suggestions on how to retrieve the 8 bit info from the bitmap?
Thanks,
7 replies
// This detects and shows 3, which is QImage::Format_Indexed8. Fine so far. qDebug()<<"alpha image format " <<alpha.format();
Watch out, you don’t have a 8bpp image, you have a 8bpp INDEXED image, so the color of each pixel is stored in the colortable (which is indexed by the value of each pixel, and stores 32bit colors).
Thanks for your replies!
I have tried the below code based on Volker’s and peppe’s replies (and based on what the documentaion says – In case of a 8-bit and monchrome images, the pixel value is only an index from the image’s color table) I seem to get what I want. If you have any comments on what I am doing, i.e if I am doing the right/wrong thing, let me know.
- // This detects and shows 3, which is QImage::Format_Indexed8. Fine so far.
- qDebug()<<"alpha image format " <<alpha.format();
- img2.setPixel(j,y,qRgba(red,gren,blue,vect.at(alpha.pixel(j,y) & 0xff)));
Only repeating a warning from the API docs on QImage::pixel() [doc.qt.nokia.com]:
Warning: This function is expensive when used for massive pixel manipulations.
It may slow down your application if you work on big images.
Only repeating a warning from the API docs on QImage::pixel() [doc.qt.nokia.com]:Warning: This function is expensive when used for massive pixel manipulations.
It may slow down your application if you work on big images.
So what’s a better alternative? QIMage::scanLine? Or reading from bits?
scanLine() can work, but be aware that you must handle the alignment of the data and all that manually.
If you have big images/and or do this often, you might consider including an external image library like GraphicsMagick [graphicsmagick.org] for the pixel manipulation. It also has a C++ interface.
You must log in to post a reply. Not a member yet? Register here!


