Donald
9/27/2004 7:09:00 PM
I'm developing a web service that receives an image file. Once I receive
that file I have to resize it and save it on the web server. This is all
working just fine with one exception - the new resized image file is larger
than the original file. For example my original file would be a bitmap with
500 X 550 px dimensions and a file size of 42.5KB...my resized image would be
a bitmap with 400 X 440 px dimensions and a file size of 171KB. How can I
get the file size to shrink with the change in dimensions? Any help would be
appreciated. Thanks!
<WebMethod()> _
Public Function ResizeAndSaveToAll(ByVal pImgFile() As Byte, ByVal
pWidth As String, ByVal pDir As String) As String
'recreate image file
Dim vSaveNewImgDir As String = "C:/temp/WebImages/Resized"
Dim oFileStream As New FileStream(vTempDir & "\" & pDir,
FileMode.Create, FileAccess.Write)
oFileStream.Write(pImgFile, 0, pImgFile.Length)
oFileStream.Close()
'manipulate image
Dim Img As Image = Image.FromFile(vTempDir & "/" & pDir)
Dim dummyCallBack As Image.GetThumbnailImageAbort
dummyCallBack = New Image.GetThumbnailImageAbort(AddressOf
DummyFunction)
Dim vImgSize As String = Img.Size.ToString
vImgSize = vImgSize.Replace("{", "")
vImgSize = vImgSize.Replace("}", "")
Dim newImgSize As String = Rescale(vImgSize, pWidth)
Dim vTemp() As String = newImgSize.Split(";")
Dim vNewWidth As String = vTemp(0)
Dim vNewHeight As String = vTemp(1)
'create & save resized image
Dim ResizedImg As Image = Img.GetThumbnailImage(vNewWidth,
vNewHeight, dummyCallBack, IntPtr.Zero)
ResizedImg.Save(vSaveNewImgDir & "/" & pDir)
ResizeAndSaveToAll = ResizedImg.Size.ToString
End Function