How to export a image with approximate size [closed]

asked 2017-10-14 13:10:49 -0600

yode gravatar image

updated 2017-10-14 15:38:29 -0600

LBerger gravatar image

I hope to get a about 400kb GPEG image whatever the input image is any size. How to implement it? This is the current image for test. Of curser, my image always grayscale,and the input image is alway greater 400kb.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-11 09:13:35.514891

Comments

1

:-P, actually not a homework somthing. I just don't start about it.. I don't beg for code,you can give me some hint. I will compose a code for it.. :) @LBerger

yode gravatar imageyode ( 2017-10-14 14:19:30 -0600 )edit

Sorry it's a mistake it was not your post. And about your problem i know only answer : 1 save image 2 get size 3 if size is greater than threshold decrease quality and goto 1

LBerger gravatar imageLBerger ( 2017-10-14 14:20:37 -0600 )edit

We have some disscuss here. we can calculate the compressed rate about the result image.But it is seem the OpenCV hard to do it. I have to say, it is not a easy problem. @LBerger

yode gravatar imageyode ( 2017-10-14 14:28:24 -0600 )edit

I don(t know what you want exactly but I think with imencode you can get image size before saving it to disk. Use imwrite flags to fixed compression quality

LBerger gravatar imageLBerger ( 2017-10-14 15:34:28 -0600 )edit