This function is available for PS and QQ images. The image size is compressed to smaller than the specified kb.
So far, I have also come to shanzhai to control the image size. The usual solution is to control the resolution and quality.
Assuming that the size of the last compression is kb, the image quality is as high as possible while ensuring that the size is not greater than kb.The higher the image quality, the larger the image size.. However, there is no fixed formula for the relationship between size and quality, such as y = nx, and I have also tried to save the pictures saved by the win7 system ten times each, from 10 to 100, we can only draw the conclusion that the image quality is high and the occupied size is large.
In this case, we can only find the most suitable quality parameter that satisfies the size of 1 ookb. The binary method is used for searching.
MemoryStream Zip(Image img, ImageFormat format, targetLen, srcLen = nearlyLen = ms = ( === targetLen *= (targetLen >== exitLen = targetLen - quality = ()Math.Floor( * targetLen / parms = EncoderParameters( ImageCodecInfo formatInfo = encoders = (ImageCodecInfo icf (icf.FormatID === startQuality = endQuality = = (startQuality + endQuality) / ( parms.Param[] = ms.SetLength(= (ms.Length >= exitLen && ms.Length <= (startQuality >= endQuality) (ms.Length < exitLen) = = newQuality = (startQuality + endQuality) / (newQuality ===
During the test, it is found that the processing time of each graph is almost 1 s. There is no problem in completing the requirement, but I always feel that there should be a more appropriate solution. If you have any friends, please kindly advise and discuss it together!
Download test code