Link to home
Start Free TrialLog in
Avatar of recruitit
recruitit

asked on

Maintaining Image/Bitmap Transparency through Graphics.Draw

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());

Open in new window

Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image



tr this


   Dim myBitmap As New Bitmap("Grapes.gif")

    ' Draw myBitmap to the screen.
    e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
    myBitmap.Height)

    ' Make the default transparent color transparent for myBitmap.
    myBitmap.MakeTransparent()   <--- this what u need

    ' Draw the transparent bitmap to the screen.
    e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
    myBitmap.Height)
Avatar of recruitit
recruitit

ASKER

Actually I have a problem, there's parts of the image that are transparent, rather than sections of the image.  Like as an example I might have a blue ball, and the background for the blue ball image is transparent, but the blue ball is also semi-transparent so that when I place it in a web browser you can see behind the blue ball.  This is unfortionetly the part that is not being transferred over is the partial transparency.
ASKER CERTIFIED SOLUTION
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah ok, thanks for the correction.  That is what I am looking for. :o)
I suppose I need to re-address the question then.
It was correct for the question being asked.