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 2 2420
Bitmaps don't have transparency when they are stored to disk do they, just
GIF? I don't know. But when reloading the image, couldn't you simply:
dim bmp as bitmap
bmp = new bitmap(<myimagefile.path>)
bmp.maketransparent(bmp.getpixel(0,0))
Just wondering.
"Mark Denardo" <ma*********@runbox.com> wrote in message
news:UY******************************@starstream.n et... 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
Well that works ok if my saved images don't have any black in them (the
non-clipped areas), but some do and it's also making those pixels
transparent as well, giving me grainy images...
"AMDRIT" <am****@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP04.phx.gbl... Bitmaps don't have transparency when they are stored to disk do they, just GIF? I don't know. But when reloading the image, couldn't you simply:
dim bmp as bitmap bmp = new bitmap(<myimagefile.path>) bmp.maketransparent(bmp.getpixel(0,0))
Just wondering.
"Mark Denardo" <ma*********@runbox.com> wrote in message news:UY******************************@starstream.n et... 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
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by Tuang |
last post: by
|
reply
views
Thread by Umesh |
last post: by
|
7 posts
views
Thread by Dobedani |
last post: by
|
1 post
views
Thread by Robert Misiak |
last post: by
|
4 posts
views
Thread by dale zhang |
last post: by
|
3 posts
views
Thread by Mark |
last post: by
|
reply
views
Thread by Robert |
last post: by
|
reply
views
Thread by Umesh |
last post: by
|
5 posts
views
Thread by Tony Clark |
last post: by
| | | | | | | | | | |