如何使用MATLAB从EPS文件中提取TIFF预览? [英] How do I extract the TIFF preview from an EPS file using MATLAB?

查看:205
本文介绍了如何使用MATLAB从EPS文件中提取TIFF预览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EPS文件可以包含嵌入式TIFF(很少有WMF)预览,以便在没有PostScript的环境中轻松呈现. (有关更多信息,请参见维基百科.)

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.)

给出这样的EPS,如何使用MATLAB将TIFF提取到单独的文件中?

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

推荐答案

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

这篇关于如何使用MATLAB从EPS文件中提取TIFF预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆