Trouble creating PNG with alpha in Magick++

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Icetigris

Trouble creating PNG with alpha in Magick++

Post by Icetigris »

Hi, I need to process an image into two 16-bit per channel RGBA pngs, but for some reason I can't edit the alpha channel. I tried doing this just to see if it would work:

Code: Select all

	size_t columns = normalMap.columns(); size_t rows = normalMap.rows();
	Color blar(0.0, UINT_MAX, 0.0, UINT_MAX);
	PixelPacket *pixels = view.get(0,0,normalMap.columns(),normalMap.rows());
	for ( ssize_t row = 0; row < rows ; ++row )
	{
	 for ( ssize_t column = 0; column < columns ; ++column )
	 {
		 blar= *pixels;
		 Color other(blar.redQuantum() / 2, blar.greenQuantum() /2, blar.blueQuantum() / 2, 0);
		 *pixels++=other; 
	 }
	}
I'm doing this to save my image:

Code: Select all

normalMap.magick("PNG64");
	normalMap.write("test.png");
It saves out an image with fine color channels, but the alpha channel is all fully opaque. Any idea what I'm doing wrong or how to save out a png with an alpha channel? Thanks.
Last edited by Icetigris on 2010-07-16T11:46:51-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble creating PNG64 with alpha in Magick++

Post by fmw42 »

normalMap.magick("PNG64");
I am not a programmer or user of APIs, just command line IM, but I don't think IM can write a PNG64 whatever that is?

see http://www.imagemagick.org/Usage/formats/#png_formats
Icetigris

Re: Trouble creating PNG64 with alpha in Magick++

Post by Icetigris »

Well it runs and makes an image fine with both PNG and PNG64 in there, just without any changes to the alpha. I need 16-bits per channel. Does Image.matte() being false tell anybody anything? Is there something I need to set so that I can get to the alpha channel?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble creating PNG with alpha in Magick++

Post by fmw42 »

Does Image.matte() being false tell anybody anything?
As I mentioned before, I do not use the APIs, but in command line if matte is off (+matte), then you have disabled the alpha channel.

If you are in IM Q16, then your produced png images will be 16 bits per channel. To create 8bits per channel then you would have to change the depth to 8. If you are in Q8 IM, then you cannot get 16-bits per channel as IM will only produce 8-bit images at best.
Icetigris

Re: Trouble creating PNG with alpha in Magick++

Post by Icetigris »

I do have the 16-bit version. I didn't modify matte myself, I'm just reading in an image and then trying write out images with alpha. How do I set matte to true?
Icetigris

Re: Trouble creating PNG with alpha in Magick++

Post by Icetigris »

Oh I think I found the problem. I was setting the images' types to TrueColorType instead of TrueColorMatteType. Now I can change the alpha channel.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Trouble creating PNG with alpha in Magick++

Post by anthony »

TrueColorMatte will have the effect of turning on Alpha.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply