且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用MATLAB从EPS文件中提取TIFF预览?

更新时间:2023-02-26 15:59:05

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