📄 createjpeg.m
字号:
function size=createJpeg(filename, r, g, b, fsize)%% size=createJpeg(filename, r, g, b, fsize)%% Creates a JPEG of the image represented by r, g, and b that is of% size fsize in bytes. It uses the jpegwrite function, and iterates% until the proper size (within 500 bytes) is reached. If the size% can't be reached, it will get as close as possible. %% set new compression valueq=100;continue=1;% upper and lower boundshighQ=100;lowQ=0;% loop until done (old and new q same, or q out of range)while continue % write the file, then open it to check the size jpgwrite(filename, r, g, b, q); jFile=fopen(filename, 'r'); fseek(jFile, 0, 'eof'); size=ftell(jFile); fclose(jFile); % show q q % are we too big or too small? if size > fsize % see if our q lower than highQ if q < highQ highQ=q; end; % too big, need to lower quality q=(q+lowQ)/2; else % see if our q bigger than lowQ if q > lowQ lowQ=q; end; % too small, need to increase quality q=(q+highQ)/2; end; if abs(size-fsize) < 500 continue=0; end; if highQ < 1 continue=0; end; if highQ-lowQ < 1 continue=0; end; end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -