插入的OLE BMP对象是这样的,前74个字节是固定的,主要包含'Bitmap Image','Paint.Pictur'等字符串和其它东西(不知道是什么),接着的4个字节是文件大小,这个大小必须是32的整数倍,不足的用0补齐,下来是文件(包括尾部用来补齐的0),最后是12个字节的尾部,倒数第4个字节实际是变化的,不知道是做什么用的,不过我用ff也没什么问题。
下面是例子程序,我没加try什么的,只是示意:
procedure TForm1.Button1Click(Sender: TObject);
const
b: array[0..73] of byte = ( // 头部
$15,$1c,$2f,$00,$02,$00,$00,$00,$0d,$00,$0e,$00,$14,$00,$21,$00,
$ff,$ff,$ff,$ff,$42,$69,$74,$6d,$61,$70,$20,$49,$6d,$61,$67,$65,
$00,$50,$61,$69,$6e,$74,$2e,$50,$69,$63,$74,$75,$72,$65,$00,$01,
$05,$00,$00,$02,$00,$00,$00,$07,$00,$00,$00,$50,$42,$72,$75,$73,
$68,$00,$00,$00,$00,$00,$00,$00,$00,$00);
e: array[0..11] of byte = ( // 尾部
$01,$05,$00,$00,$00,$00,$00,$00,$ff,$ad,$05,$fe);
zero: byte = 0; // 补齐的0
var
bs: TADOBlobStream;
fs: TFileStream;
size, len, i: integer; // 文件大小,写入OLE的长度(32的整数倍)
begin
fs := TFileStream.Create('E:/pic/b3711.bmp', fmOpenRead);
size := fs.Size;
len := size + 32 - (size mod 32);
ADOTable1.Edit;
bs := TADOBlobStream.Create(TBlobField(ADOTable1.FieldByName('photo')), bmWrite);
bs.Write(b, 74);
bs.Write(len, 4);
bs.CopyFrom(fs, 0);
for i := 1 to len - size do
bs.Write(zero, 1);
bs.Write(e, 12);
bs.Free;
ADOTable1.Post;
fs.Free;
end;