Vim下编辑二进制文件方法

来源:互联网 发布:域名不续费会怎么样 编辑:程序博客网 时间:2024/05/16 07:37

参考:http://www.blogjava.net/ivanwan/archive/2006/02/20/31657.html

问题说明:

在Ubuntu下使用tifftopnm处理tiff数据时,总是出现提示:

TIFFReadDirectory: Warning, 005179_2.tif: unknown field with tag 33550 (0x830e) encountered.TIFFReadDirectory: Warning, 005179_2.tif: unknown field with tag 33922 (0x8482) encountered.TIFFReadDirectory: Warning, 005179_2.tif: unknown field with tag 34735 (0x87af) encountered.tifftopnm: writing PGM file005179_2.tif: Can not read scanlines from a tiled image.tifftopnm: Unable to read row 0, plane 0 of input Tiff image.  TIFFReadScanline() failed.



而在安装完tifflib之后,调用tifflib-tools,tiffinfo显示如下:

TIFFReadDirectory: Warning, 005179_2.tif: unknown field with tag 33550 (0x830e) encountered.TIFFReadDirectory: Warning, 005179_2.tif: unknown field with tag 33922 (0x8482) encountered.TIFFReadDirectory: Warning, 005179_2.tif: unknown field with tag 34735 (0x87af) encountered.TIFF Directory at offset 0x200232 (2097714)  Image Width: 703 Image Length: 676  Tile Width: 512 Tile Length: 512  Resolution: 1, 1 (unitless)  Bits/Sample: 16  Sample Format: unsigned integer  Compression Scheme: None  Photometric Interpretation: min-is-black  Orientation: row 0 top, col 0 lhs  Samples/Pixel: 1  Planar Configuration: single image plane  Software: IMAGINE TIFF SupportCopyright 1991 - 1999 by ERDAS, Inc. All Rights Reserved@(#)$RCSfile: etif.c $ $Revision: 1.10.1.9.1.9.2.11 $ $Date: 2004/09/15 18:42:01EDT $  Tag 33550: 0.025400,0.025400,0.000000  Tag 33922: 0.000000,0.000000,0.000000,393.954788,595.326391,0.000000  Tag 34735: 1,1,0,2,1024,0,1,0,1025,0,1,1

所以尝试着利用vim查看tiff源文件,参考方法如下:


一个真正的二进制编辑器用两种方式来显示文本: 二进制和十六进制格式。你可以在 Vim

里通过转换程序 "xxd" 来达到这效果。该程序是随 Vim 一起发布的。
   首先以二进制方式编辑这个文件:

        vim -b datafile

现在用 xxd 把这个文件转换成十六进制:

        :%!xxd

文本看起来像这样:

        0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49  ....9..;..tt.+NI
        0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30  K,.`.....b..4^.0
        0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9  7;'1.".....i.59.

现在你可以随心所欲地阅读和编辑这些文本了。 Vim 把这些信息当作普通文本来对待。
修改了十六进制部分并不导致可打印字符部分的改变,反之亦然。
   最后, 用下面的命令把它转换回来:

        :%!xxd -r

只有十六进制部分的修改才会被采用。右边可打印文本部分的修改忽略不计。
0 0
原创粉丝点击