This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
MattW  
#1 Posted : Tuesday, July 14, 2009 3:29:53 AM(UTC)
MattW

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
Tamila  
#2 Posted : Tuesday, July 14, 2009 2:20:54 PM(UTC)
Tamila

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 Support Team

UserPostedImage Follow Aurigma on Twitter!
Users browsing this topic
Guest (3)
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.