troubleshooting Question

Maintaining Image/Bitmap Transparency through Graphics.Draw

Avatar of recruitit
recruitit asked on
Web Graphics SoftwareASPC#
6 Comments1 Solution418 ViewsLast Modified:
Is there anyway of maintaining an images transparency/alpha channel for pngs when using System.Drawing.Graphics.DrawImage.

What I am basically doing is overlapping 4 or 5 images that all have transparency, but the transparency is being lost in the process, the code being used is shown below
System.Drawing.Image frmImg = System.Drawing.Bitmap.FromFile(framePath);
        System.Drawing.Graphics frame = System.Drawing.Graphics.FromImage(frmImg);
        frame.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        frame.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        
 
        // Setup the Shadow and Mount
        System.Drawing.Image shadow = System.Drawing.Bitmap.FromFile(shadowPath);
 
        // Draw the Picture
        System.Drawing.Image picture = System.Drawing.Bitmap.FromFile(MapPath(imgUrl));
        frame.DrawImage(picture, 44, 38, 260, 185);
 
        // If it has a mount then draw the mount
        if (hasMount)
        {
            System.Drawing.Image mountCore = System.Drawing.Bitmap.FromFile(mountCorePath);
            frame.DrawImage(mountCore, new System.Drawing.Point(0, 0));
        }
 
        // Draw Shadow
        frame.DrawImage(shadow, new System.Drawing.Point(0, 0));
        
        
 
        // Respond with a PNG image to the browser
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        frmImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        Response.BinaryWrite(ms.GetBuffer());
ASKER CERTIFIED SOLUTION
Melih SARICA
Melih SARICA

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros