Hey thanks, that worked out pretty well. I'd like to expand on it a little
though. Here's the situation:
User uploads a color photo for an advertisement. Certain ads are black and
white, others are color. The client wants to receive ALL images in color,
however when it's displayed to the user on the Ad Confirmation screen, if
they've ordered a B&W ad, they should see it in B&W.
To me, the best way to accomplish this would just be to load the B&W image
in memory, bypassing any file system operations and then to assign the image
in memory to the ImageUrl property of the Image control. This way, the user
sees the B&W image that is loaded in memory, but the client receives the
original image in color.
I've used your function, along with another one that converts the Gif or
Jpeg image to Bitmap. Here is the other function:
Public Sub ConvertImage(ByVal Filename As String, _ ByVal DesiredFormat As
System.Drawing.Imaging.ImageFormat, _ ByVal NewFilename As String)
' Takes a filename and saves the file in a new format
Try
Dim imgFile As System.Drawing.Image = _
System.Drawing.Image.FromFile(Filename)
imgFile.Save(NewFilename, DesiredFormat)
Catch ex As Exception
Throw ex
End Try
End Sub
I have two problems with this setup:
1) I end up with 3 files for every one uploaded (the original color, the
converted BitMap, the resultant greyscale image).
2) There seems to be a lock on the original image file once this conversion
has taken place. It cannot be overwritten after these functions are run.
What would I need to change in these two functions so that I can take a
color image on the file system, convert it to BitMap and then GreyScale in
memory, then assign that image in memory to the ImageUrl property of the
Image control? I'll be researching this on my own also, but I figured I'd
ask here as well, just in case. ;-)
Thanks,
Scott