How do I extract the TIFF preview from an EPS file using MATLAB?

允我心安 提交于 2020-01-25 06:10:49

问题


EPS files can include embedded TIFF (and rarely WMF) previews for easy rendering in environments which do not have PostScript available. (See Wikipedia for more info.)

Given such an EPS, how can I extract the TIFF into a separate file using MATLAB?


回答1:


% Define the source EPS file and the desired target TIFF to create.
source = 'ode_nonneg1.eps';
target = 'ode_nonneg1.tif';

% Read in the EPS file.
f = fopen(source,'rb');
d = fread(f,'uint8');
fclose(f);

% Check the header to verify it is a TIFF.
if ~isequal(d(1:4),[197;208;211;198])
    error 'This does not appear to be a vaild TIFF file.'
end

% Extract the TIFF data location from the headers.
tiffStart = sum(d(21:24).*256.^(0:3)')+1;
tiffLength = sum(d(25:28).*256.^(0:3)');

% Write the TIFF file.
f = fopen(target,'w');
fwrite(f,d(tiffStart:tiffStart-1+tiffLength),'uint8','b');
fclose(f);


来源:https://stackoverflow.com/questions/17751052/how-do-i-extract-the-tiff-preview-from-an-eps-file-using-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!