从Access 2002 VBA导出重新创建Tiff图像

时间:2014-01-14 22:16:25

标签: vba ms-access access-vba tiff libtiff.net

我有一组旧的Access 2002表单,远程开发人员使用VBA命令SaveToText()执行导出到平面文本文件。结果文件类似于:

Version =20
VersionRequired =20
Checksum =2050894001
Begin Form
AllowDesignChanges = NotDefault
...
// Other data
...
Begin Image
    Left =420
    Top =2940
    Width =15
    Height =15
    Name ="OnePixelWhite"
    PictureData = Begin
        0x0e000000b23c467d010000006c00000000000000000000000000000000000000 ,
        0x00000000000000001a0000001a00000020454d46000001004403000011000000 ,
        0x010000000000000000000000000000000005000000040000c401000069010000 ,
        0x000000000000000000000000e3e306001c830500460000009401000088010000 ,
        0x4744494301000080000300008e2be2fd0000000070010000010009000003b800 ,
        0x00000000440000000000050000000c0201000100040000000301080005000000 ,
        0x0b0200000000050000000c02010001000f00000026060f0014005f464d524941 ,
        0x21202020202420202020202220201300000026060f001c005f464d5244412020 ,
        0x2020203020202020202020402020215c2f2020204400000026060f007e005f46 ,
        0x4d5246534c205030204823203c213035202c27204521403c202c27203c21403c ,
        0x203827204121203b2050262045213039205025203021303a202c26205421303d ,
        0x202827204521503c205025202f21403b203426203021303a204027204521203b ,
        0x203c25204821303a203027204521402b20302720492140392020202005000000 ,
        0x07010300000005000000090200000000050000000102ffffff0024000000430f ,
        0x2000cc0000000100010000000000010001000000000028000000010000000100 ,
        0x0000010018000000000004000000c40e0000c40e00000000000000000000ffff ,
        0xff00030000000000110000000c000000080000000b0000001000000001000000 ,
        0x0100000009000000100000000100000001000000090000001000000001000000 ,
        0x010000000a000000100000000000000000000000090000001000000001000000 ,
        0x01000000150000000c00000003000000180000000c0000000000000019000000 ,
        0x0c000000ffffff00510000007c00000000000000000000000000000000000000 ,
        0x0000000000000000000000000000000001000000010000005000000028000000 ,
        0x7800000004000000000000002000cc0001000000010000002800000001000000 ,
        0x01000000010018000000000004000000c40e0000c40e00000000000000000000 ,
        0xffffff00250000000c00000007000080250000000c0000000000008030000000 ,
        0x0c0000000f0000804b0000001000000000000000050000000e00000014000000 ,
        0x000000001000000014000000
    End
    Picture ="C:\\Users\\rvallee\\Pictures\\OnePixelWhite.tif"
    GUID = Begin
    0x2ca8b15c250c5f449ef3092a21427c14
End

有没有人有微软如何编码Tiff数据的指南?它们似乎完全剥离了标准的Tiff标头,我无法理解结果数据以找到任何图像文件目录。

我已经设法拼凑了一些类来创建一个新的图像标题和图像文件目录,但我真的想确定用于正确检索原始IFD中的Tiff实体的编码。

1 个答案:

答案 0 :(得分:0)

事实证明,数据是作为EMF文件嵌入的。如果我们剥离前8个字节的数据,文件的其余部分可以直接实例化为Image对象。

var file = File.ReadAllLines(filePath);
var fileBytes = new List<byte>();
foreach (string line in file)
{
    var numberChars = hex.Length / 2;
    var lineBytes = new byte[numberChars];
    using (var sr = new StringReader(hex))
    {
        for (var i = 0; i < numberChars; i++)
        lineBytes [i] = Convert.ToByte(new string(new[] { (char)sr.Read(), (char)sr.Read() }), 16);
    }
    fileBytes.AddRange(lineBytes);
}
fileBytes.RemoveRange(0, 8);
var ms = new MemoryStream(fileBytes.ToArray());
var image = Image.FromStream(ms);
image.Save("test.emf");