Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hi all,

I need to change the size of many jpg images to be 3.8 kilobytes.

I tried the EncoderParameter epQuality = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, val);
But I am not able to make the image reach a specific size in Kb.

Can anyone help?
Posted
Updated 27-Mar-11 6:11am
v2
Comments
Piccadilly Yum Yum 27-Mar-11 11:30am    
size of encoded image depends by its content, same quality on diffrent image leads to diffrent sizes. so algorithm is not yet calibrated on resulting image size..
Mohammad Al Hoss 27-Mar-11 11:44am    
I tried to save the image with percent value to 50 then see what is the size in bytes, then based on the new image size I calculate the new percent but also not working well.

Is there any other way to do this, other methods or something.
Piccadilly Yum Yum 27-Mar-11 11:50am    
you should study jpeg compression to understant if a way exist to you. look at there :
http://www.prepressure.com/library/compression_algorithms/jpeg
Mohammad Al Hoss 27-Mar-11 11:52am    
thanks.
Steve Wellens 27-Mar-11 11:42am    
Do you mean 3.8k on disk?
Jpeg images are not compressed until they are saved.
The size is dependent on the image content and compression level.
A klunky, crude way would be to save two temporary images with a high and a low compression. Check their sizes and interpolate what the compression level should be.

You cannot specify the resulting binary size of the JPEG. The only way to do what you want would be to incrementally reduce the Quality value and resave the image over and over again until it meets your specification. The problem with this is that you could reduce the Quality so low as to make the image unrecognizable.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Mar-11 16:28pm    
Correct, a 5.
--SA
Upload the image to PAINT and reduce it, then save it as the smaller file.
Or, email it to yourself, that also gives a reduction option.

Picture quality is the price you pay though.

Another hint to to trim away the edges of the unimportant material or background.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Mar-11 16:29pm    
Dalek, whatever you do, you cannot guarantee you meet the requirement of the file size.
(I did not vote)
--SA
Hello, I need a sample code to reduce the size but actual quality like facebook. If any SDK, took or code..? any body can help me.?
 
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