473,216 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

Troubled saving a clipped region from an image to disk as transparent

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







May 3 '06 #1
2 2492
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







May 3 '06 #2
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








May 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tuang | last post by:
Given a URL for an MP3 audio stream, how could I write a little utility that would start the stream flowing, capture it to a disk file, and then disconnect from the stream? I'm imagining that, for...
0
by: Umesh | last post by:
Hi, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this stream as a...
7
by: Dobedani | last post by:
Dear All, I am developing / maintaining a web application which generates GIF images on the fly. When I send the image, I make sure a header is sent first with MIME-type image/gif. My HTML-code...
1
by: Robert Misiak | last post by:
Is it possible to save an embedded resource as a real file on the local disk? Robert
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
3
by: Mark | last post by:
Hi, I have put together a script in C# that takes a text file, then streams it into a SQLServer database. What I am trying to do now is create another script that does the exact opposite: selects...
0
by: Robert | last post by:
I have put an WebForms.Image Control in my projec Set the BackColor & BorderColor to Transparen I have designed an image in theImage.aspx file of my projec & use MakeTransparent method to make it...
0
by: Umesh | last post by:
Hi Gurus, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this...
5
by: Tony Clark | last post by:
Hi, I have a bmp that is set in a panel, i want to make the white color in the bmp image transparent so i can see the color of the panel below. How is this done? thanks tony
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.