Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
PSD with transparent background goes black when converting to JPG
Rank: Newbie
Groups: Guest
Joined: 6/24/2009(UTC) Posts: 3
|
When using the following code to read / resize and output a PSD as a JPG, the transparent background is output as black. Is there a way to have this output as white? Code:
Bitmap ModifiedBitmap = new Bitmap();
PsdReader PSD = new PsdReader(@"c:\PSDs\My.psd");
IFrame PSDFrame = PSD.LoadFrame(0);
PSDFrame.GetBitmap(ModifiedBitmap);
ModifiedBitmap.Transforms.Resize(Width, Height, InterpolationMode.Lanczos3Filter);
//Specify that we are going to save to JPEG
JpegEncoderOptions EncoderOptions = new JpegEncoderOptions(95, true);
//Save image to response stream
context.Response.Clear();
context.Response.ContentType = "image/jpeg";
ModifiedBitmap.Save(context.Response.OutputStream, EncoderOptions);
ModifiedBitmap.Dispose();
context.Response.End();
Thanks, Matt
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 3/9/2008(UTC) Posts: 554
Was thanked: 1 time(s) in 1 post(s)
|
Hello Matt, You just need to discard alpha channel and set necessary background color. You can do it as follows: Code:Bitmap ModifiedBitmap = new Bitmap();
PsdReader PSD = new PsdReader(@"c:\PSDs\My.psd");
IFrame PSDFrame = PSD.LoadFrame(0);
PSDFrame.GetBitmap(ModifiedBitmap);
ModifiedBitmap.Transforms.Resize(Width, Height, InterpolationMode.Lanczos3Filter);
Aurigma.GraphicsMill.Color background = System.Drawing.Color.White;
ModifiedBitmap.Channels.DiscardAlpha(background);
//Specify that we are going to save to JPEG
JpegEncoderOptions EncoderOptions = new JpegEncoderOptions(95, true);
//Save image to response stream
context.Response.Clear();
context.Response.ContentType = "image/jpeg";
ModifiedBitmap.Save(context.Response.OutputStream, EncoderOptions);
ModifiedBitmap.Dispose();
context.Response.End();
|
|
|
|
|
Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
PSD with transparent background goes black when converting to JPG
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.