Not Flattening When Saving JPG [SOLVED]

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Posts: 11
Joined: 2012-08-20T09:03:33-07:00
Authentication code: 67789

Not Flattening When Saving JPG [SOLVED]

Post by insomniacp »

Using the below code shows that when converting a png with alpha channels to a jpg image the alpha channels are not flattened but simply removed. I am wondering if there is a way to flatten the pixels before or during conversion so that the semi transparent pixels still retain the color they appear to have but are fully opaque due to being in a jpg. I could not locate any way to do this manually before saving so I am unsure how to proceed if I need to write my own function or not. I know ImageMagick itself does have the ability to flatten so I am assuming that it is accessible through the magick++ interface.

Code: Select all

#include <Magick++.h> 
#include <iostream>
using namespace std;
using namespace Magick;
int main()
	Image test;
	string url = "";
	} catch(Exception e)
		cout <<e.what()<<endl;
		cout <<"writing file"<<endl;
		} catch(Exception e)
			cout <<"something bad happened "<<e.what()<<endl;
	cout <<"done with program"<<endl;
	return 0;
Last edited by insomniacp on 2012-08-30T09:24:37-07:00, edited 1 time in total.

User avatar
Site Admin
Posts: 11158
Joined: 2003-05-31T11:32:55-07:00

Re: Not Flattening When Saving JPG

Post by magick »

You need to call MagickCore::MergeImageLayers() with MagickCore::FlattenLayer. In the mean-time we'll a Magick++ mergeLayers() method in the next point release of ImageMagick.

Post Reply