PDA

View Full Version : Qpixmap of 32 bit Depth



augusbas
19th May 2011, 05:59
Dear all,

One of my third party library needs a Qpixmap which should be of ARGB(32) format to enable the transparency. By default in Linux Qpixmap is of 24 bit depth.

I have tried the below method for conversion and passed the Qpixmap, and still it shows as 24 bit depth....How do i create a pixmap of 32 bit depth in Qt.




QImage overlay_image(768,768,QImage::Format_ARGB32);

bool loaded = overlay_image.load ("/aegea.png", 0 );

QPixmap overlay_map;

overlay_map= overlay_map.fromImage ( overlay_image,Qt::AutoColor );



Please advice me..

ChrisW67
19th May 2011, 07:06
What is the data in aegea.png, because it is this you are manipulating (you discard the unitialised Format_ARGB32 QImage)? Are you doing anything with the QImage other than loading the file? If not, then why not just load the QPixmap directly?

My example image is identified (ImageMagick) as:


$ identify -verbose plane.png
Image: plane.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 1040x138+0+0
Resolution: 72x72
Print size: 14.4444x1.91667
Units: Undefined
Type: TrueColorMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit
...

and is a mostly transparent banner of an aircraft with partial transparency of the spinning propeller. This code:


// Your code with adjustment for static method
QImage overlay_image(768,768,QImage::Format_ARGB32);
bool loaded = overlay_image.load ("plane.png", 0 );
QPixmap overlay_map = QPixmap::fromImage ( overlay_image,Qt::AutoColor );
qDebug() << loaded;
qDebug() << overlay_map.size() << overlay_map.depth() << overlay_map.hasAlphaChannel();

// Load the PNG directly
overlay_map.load("plane.png");
qDebug() << overlay_map.size() << overlay_map.depth() << overlay_map.hasAlphaChannel();

outputs


true
QSize(1040, 138) 32 true
QSize(1040, 138) 32 true

on Linux, Qt 4.7.2.

augusbas
19th May 2011, 07:56
Hi Chris,

I did the same and found the properties of my image as below:

I think it doesnt have alpha : 8 bit


identify -verbose aegean-120km.png
Image: aegean-120km.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 1292x1001+0+0
Resolution: 37.79x37.79
Print size: 34.1889x26.4885
Units: PixelsPerCentimeter
Type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
red:
min: 0 (0)
max: 235 (0.921569)
mean: 54.9768 (0.215595)
standard deviation: 22.5171 (0.0883024)
kurtosis: 1.95082
skewness: 0.869281
green:
min: 3 (0.0117647)
max: 243 (0.952941)
mean: 74.8666 (0.293594)
standard deviation: 21.6226 (0.0847946)
kurtosis: 1.41052
skewness: 0.226536
blue:
min: 1 (0.00392157)
max: 241 (0.945098)
mean: 93.5669 (0.366929)
standard deviation: 31.2464 (0.122535)
kurtosis: -0.907665
skewness: -0.429502
Image statistics:
Overall:
min: 0 (0)
max: 243 (0.952941)
mean: 55.8526 (0.21903)
standard deviation: 41.3977 (0.162344)
kurtosis: -0.988763
skewness: 0.0747025
Rendering intent: Saturation
Gamma: 0.45455
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Interlace: None
Background color: rgb(1,1,1)
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Page geometry: 1292x1001+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2011-05-19T10:17:37+06:00
date:modify: 2010-11-29T18:15:51+06:00
signature: e48cd3c45e0ab3014e55d9ae6f51de1d41f485add63ec622c0 74a58b31a39933
Artifacts:
verbose: true
Tainted: False
Filesize: 1.372mb
Number pixels: 1.233mb
Version: ImageMagick 6.5.4-7 2010-02-26 Q16 OpenMP http://www.imagemagick.org




I did the same of loading the PNG directly for me on both the cases it gives me a depth of 24 bit.....



true
QSize(1292, 1001) 24 false
QSize(1292, 1001) 24 false



Anything i have to try chris .....

Added after 26 minutes:

Hi chris,

I tried this, it sets my pixmap to 32 bit ......


overlay_map.load("/aegean-60km.bmp");

qDebug() << overlay_map.size() << overlay_map.depth() << overlay_map.hasAlphaChannel();

overlay_map.setAlphaChannel(QPixmap("/aegean-60km.bmp"));

qDebug() << overlay_map.size() << overlay_map.depth() << overlay_map.hasAlphaChannel();


QSize(1292, 1076) 24 false
QSize(1292, 1076) 32 true

Now i didnt get any error .....This is the right way to set the pixmap to 32 Bit depth....

ChrisW67
19th May 2011, 10:29
No, the right way would be to create a PNG file with an alpha channel in the first place. The setAlphaChannel() method is obsolete and likely to disappear.

If you really cannot supply a source image with an alpha channel then you could load it into a QImage and use QImage::convertToFormat()

augusbas
19th May 2011, 12:03
No, the right way would be to create a PNG file with an alpha channel in the first place. The setAlphaChannel() method is obsolete and likely to disappear.

If you really cannot supply a source image with an alpha channel then you could load it into a QImage and use QImage::convertToFormat()


OK Chris, i will follow the same ....

Thank you for your support Chris...:)