[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

GetThumbnailImage increases file size

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
2 Answers

the.duckman

9/30/2004 5:31:00 PM

0

G''Day mate.

Im not to sure if Im reading your code right but
ResizeAndSaveToAll = ResizedImg.Size.ToString is not nessesarly the
size of your new file.

Anyways Im probably on the wrong track there.
Now a 500x550 bitmap image @ 8bpp would ocupy about 275kb of data.
That your orignial image was only 42k suggests it was using rle
compression (google this if your not to sure what Im yapping about).

Your new image lets see 400x440 = 176,000 bytes theres your 176kb. So
its safe to assume that your second image does not use rle compression
hence your discrepency.

Anyways you can set the compression trivialy. But let me point out
something.

The bmp format is generaly not suitable for thumbnails. _especialy_
for web use.

What you must consider is two points:

1st the resampling performed on bitmaps can degrade the rle
compressability of and image if the resize is small (as in your case).
This happens in many ways but maily because pixels are blended
together and the length of consequative identical pixel sequences is
reduced. This can also cause your image to grow even after you fix
your rle problems. The bmp picture tubnails will only achive modest
savings until you reach 50%(rough number) or greater size reduction.

2nd the jpeg format with compression set to the 30% range (ie very
lossy) performs well for tumbnail sized images around 64x64. This is a
much better thumnail solution as file sizes are _extremly_ small and
with the small size of the image visual aritfacts are less noticable.
(If you don''t belve me on this try it and the results will speek for
them selves).

-dm




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.
>
>
> ''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

Pascal

8/13/2008 4:53:00 PM

0

David Richerby a ?crit :
> Andy Duplain <trojanfoe@googlemail.com> wrote:
>> There is more than one open source chess database
>
> True but SCID seems to be the one that's most talked-about.
> (Admittedly, round here that's partly because there's a certain amount
> of controversy about Pascal's version of it.)

Usssssh ! don't wake up the trolls ;-) !

FYI, there seems to be no fork of Scid really maintained those days (I
may be wrong), and Scid (the Genuine one), is (see
http://scid.sourc...).

If you look at
http://sourceforge.net/mailarchive/forum.php?forum_name=...
for latest months activity you will see that Scid's development is up
and well.

To come back to this post's subject, a format must proove its efficiency
first, then (and only then) *maybe* become a de facto standard (only if
this format is far better than all others). The first phase of the
process (development and qualification) is certainly many years long.

Pascal