我如何提取使用MATLAB的EPS文件的TIFF预览?(How do I extract the T

2019-10-18 09:30发布

EPS文件可以包含嵌入的TIFF(而且很少WMF)的环境中容易渲染预览不具备的PostScript可用。 (参见维基百科的更多信息。)

鉴于这样的EPS中,我怎么能提取到TIFF利用MATLAB一个单独的文件?

Answer 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);


文章来源: How do I extract the TIFF preview from an EPS file using MATLAB?
标签: matlab tiff eps