【问题标题】:How do I extract the TIFF preview from an EPS file using MATLAB?如何使用 MATLAB 从 EPS 文件中提取 TIFF 预览?
【发布时间】:2013-07-19 16:26:57
【问题描述】:

EPS 文件可以包含嵌入式 TIFF(很少是 WMF)预览,以便在没有可用 PostScript 的环境中轻松呈现。 (有关更多信息,请参阅Wikipedia。)

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

【问题讨论】:

    标签: matlab tiff eps


    【解决方案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);
    

    【讨论】:

    • +1 也许您可以只读取 TIFF 预览,而不必读取内存中的整个 EPS 文件(通过从文件中读取前 28 个字节,然后使用 fseek 并读取指定范围)
    猜你喜欢
    • 2013-05-16
    • 1970-01-01
    • 2012-02-03
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    相关资源
    最近更新 更多