Click here to Skip to main content
15,914,109 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have scan an A4 size Image with 100 dpi as '.tif' format. The file size stand 2832 KB. Now I want to reduce the file size to 50 KB.

I have already try to reduce the bit depth such as ...

dim SourceName As String = "C:\Sample.tif"
dim TargetName As String = "C:\Sample_Compress.tif"
Dim tiff As Image
Dim enParams As New EncoderParameters(2)
Dim tifCodec As ImageCodecInfo = ImageCodecInfo.GetImageEncoders(3)

enParams.Param(0) = New EncoderParameter(Encoder.Compression,
EncoderValue.CompressionLZW)

enParams.Param(1) = New EncoderParameter(Encoder.Quality, CLng(1))


tiff = Image.FromFile(SourceName )
Dim tempBM As New Bitmap(tiff.Width, tiff.Height, PixelFormat.Format32bppArgb)

tempBM.SetResolution(tiff.HorizontalResolution, tiff.VerticalResolution)
Dim g1 As Graphics = Graphics.FromImage(tempBM)


g1.DrawImageUnscaled(tiff, New Point(0, 0))
tempBM.Save(TargetName, tifCodec, enParams)
tiff.Dispose()

--------------------

Now the file size reduce to 2832 KB to 400 KB. How can I reduce to 50 KB ?
Posted
Updated 10-Oct-14 2:19am
v3
Comments
Sergey Alexandrovich Kryukov 10-Oct-14 9:31am    
What was the original pixel format? 64 bits per pixel or what?
—SA

1 solution

Who told you that you can compress the file to any predefined value? :-) You already have LZW (lossless) compression and got pretty good results.

Well, you can get less bits per pixel. If you don't need opacity layer, PixelFormat.Format24bppRgb is still quite good. Going down… is possible but usually looks ugly. Also, it depends on the image. If you have limited number of colors (geometric graphics), PixelFormat.Format1bppIndexed, but this is a rare situation. You can go anywhere lower, but I doubt you can get good results this way. Please see: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat%28v=vs.110%29.aspx[^].

Other than that — you can move to the field of lossy compression, such as JPEG or lossy PNG. One warning: never edit images saving results using lossy compression: the artifacts of compression will accumulate and deteriorate the image quality beyond repair. The compression should be done only once. Use only lossless compression for any intermediate results. Please see:
http://en.wikipedia.org/wiki/Lossless_compression[^],
http://en.wikipedia.org/wiki/Lossy_compression[^],
http://en.wikipedia.org/wiki/JPEG[^],
http://en.wikipedia.org/wiki/Portable_Network_Graphics#Compression[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900