M
Mark Denardo
Hi, I need some expert GDI+ person to help me with my RoundOffImage
Function:
What I'm trying to do is take in an image, crop off the edges around an
ellipse region I set up, and then return the cropped image from the
function. I sort of have this working, but not thoroughly.
If I take the output image of this function and draw it on my form it shows
the clipped image as transparent as I am wanting it. But if I take that
image and save it to disk:
m_RoundedCroppedImage.Save(....)
Then the clipped region is showing up as black in the saved file. What is
going on and how do I make it transparent and not black?
I'm assuming it's something I need to do while saving it, or do I need to
add something to my function to set up the image before saving it to file?
Note: I tried adding the following line (before I clip it) which I picked up
somewhere in a GDI discussion, but it doesn't help.
=> CropGraphic.Clear(Color.FromArgb(0, 0, 0, 0)), so I left it out
Public Function RoundOffImage(ByVal SrcImage As Image) As Image
Dim gpCutEllipse As New System.Drawing.Drawing2D.GraphicsPath
Dim SrcBitmap As Bitmap = New Bitmap(SrcImage)
Dim CropBitmap As New Bitmap(SrcImage.Width, SrcImage.Height,
SrcBitmap.PixelFormat)
Dim CropGraphic As Graphics
Dim SrcRect As New Rectangle(0, 0, SrcImage.Width, SrcImage.Height)
' Create region for clipping.
gpCutEllipse.AddEllipse(SrcRect)
CropGraphic = Graphics.FromImage(CropBitmap)
' Set clipping region of graphics to region.
CropGraphic.SetClip(gpCutEllipse)
CropGraphic.DrawImage(SrcImage, 0, 0)
Return CropBitmap
End Function
Can any body help me out?
Mark
Function:
What I'm trying to do is take in an image, crop off the edges around an
ellipse region I set up, and then return the cropped image from the
function. I sort of have this working, but not thoroughly.
If I take the output image of this function and draw it on my form it shows
the clipped image as transparent as I am wanting it. But if I take that
image and save it to disk:
m_RoundedCroppedImage.Save(....)
Then the clipped region is showing up as black in the saved file. What is
going on and how do I make it transparent and not black?
I'm assuming it's something I need to do while saving it, or do I need to
add something to my function to set up the image before saving it to file?
Note: I tried adding the following line (before I clip it) which I picked up
somewhere in a GDI discussion, but it doesn't help.
=> CropGraphic.Clear(Color.FromArgb(0, 0, 0, 0)), so I left it out
Public Function RoundOffImage(ByVal SrcImage As Image) As Image
Dim gpCutEllipse As New System.Drawing.Drawing2D.GraphicsPath
Dim SrcBitmap As Bitmap = New Bitmap(SrcImage)
Dim CropBitmap As New Bitmap(SrcImage.Width, SrcImage.Height,
SrcBitmap.PixelFormat)
Dim CropGraphic As Graphics
Dim SrcRect As New Rectangle(0, 0, SrcImage.Width, SrcImage.Height)
' Create region for clipping.
gpCutEllipse.AddEllipse(SrcRect)
CropGraphic = Graphics.FromImage(CropBitmap)
' Set clipping region of graphics to region.
CropGraphic.SetClip(gpCutEllipse)
CropGraphic.DrawImage(SrcImage, 0, 0)
Return CropBitmap
End Function
Can any body help me out?
Mark