你如何提取从TGraphicField位图? [英] How do you extract a bitmap from a TGraphicField?
本文介绍了你如何提取从TGraphicField位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要疯了。
下面是我在做什么。
- 放入一个TClientDataSet,一个的TImage,并在窗体上一个TButton。
- 将Clientdataset1.Filename到biolife.xml
-
按钮双击并添加下列code:
程序TForm31.Button1Click(发件人:TObject的);
VAR
BF:TBlobField;
BS:TStream;
BM:TBitmap;
开始
ClientDataset1.Open;
ClientDataset1.First;
BF:= ClientDataSet1.FieldByName('平面')作为TBlobField;
BS:= ClientDataSet1.CreateBlobStream(BF,bmRead);
BS.Position:= 0;
BM:= TBitmap.Create;
尝试
BM.LoadFromStream(BS);
最后
BM.Free;
结束;
结束;
运行它。当我这样做,我得到位图图像无效。
咦?该数据一直是位年 - ?什么是错
解决方案
图形字段是二进制大对象(BLOB)领域,其中的一种形式
在数据包括BLOB头描述的编码
图形化的价值。
块引用>BLOB头是误导那里,它似乎是图形备忘录悖论存储格式的残余。
(*从DB *){悖论图形BLOB头}
类型
TGraphicHeader =记录
字数:字; {1}固定
HTYPE:字; {在$ 0100固定}
尺寸:Longint型; {尺寸不包括报头}
结束;
程序TForm1.FormClick(发件人:TObject的);
常量
HeaderSize =中SizeOf(TGraphicHeader);
VAR
现场:TGraphicField;
流:TClientBlobStream;
开始
现场:= ClientDataSet1.FieldByName('平面')作为TGraphicField;
流:= ClientDataSet1.CreateBlobStream(场,bmRead)为TClientBlobStream;
Stream.SaveToFile('dump.bin'); //检查BLOB,看到额外的字节preceding BITMAPFILEHEADER
断言(Stream.Position = 0);
Stream.Seek(+ HeaderSize,soFromCurrent); //丢弃报头,它不包含使用任何反正
Image1.Picture.Bitmap.LoadFromStream(流); ClientDataSet1.Next;
结束;I am going nuts.
Here's what I am doing
- Drop a TClientDataset, a TImage, and a TButton on a form.
- Set the Clientdataset1.Filename to biolife.xml
Double click on the button and add the following code:
procedure TForm31.Button1Click(Sender: TObject); var BF: TBlobField; BS: TStream; BM: TBitmap; begin ClientDataset1.Open; ClientDataset1.First; BF := ClientDataSet1.FieldByName('Graphic') as TBlobField; BS := ClientDataSet1.CreateBlobStream(BF, bmRead); BS.Position := 0; BM := TBitmap.Create; try BM.LoadFromStream(BS); finally BM.Free; end; end;
Run it. When I do, I get "Bitmap image is not valid".
Huh? That data has been a bitmap for years -- what is wrong?
解决方案Graphics fields are a form of binary large object (BLOB) field where the data includes a BLOB header describing the encoding of the graphical value.
"BLOB header" is misleading there, it appears to be a remnant of Paradox storage format for graphic memos.
(* from DB *) { Paradox graphic BLOB header } type TGraphicHeader = record Count: Word; { Fixed at 1 } HType: Word; { Fixed at $0100 } Size: Longint; { Size not including header } end; procedure TForm1.FormClick(Sender: TObject); const HeaderSize = SizeOf(TGraphicHeader); var Field: TGraphicField; Stream: TClientBlobStream; begin Field := ClientDataSet1.FieldByName('Graphic') as TGraphicField; Stream := ClientDataSet1.CreateBlobStream(Field, bmRead) as TClientBlobStream; Stream.SaveToFile('dump.bin'); // examine BLOB and see extra bytes preceding BITMAPFILEHEADER Assert(Stream.Position = 0); Stream.Seek(+HeaderSize, soFromCurrent); // discard header, it does not contain anything of use anyways Image1.Picture.Bitmap.LoadFromStream(Stream); ClientDataSet1.Next; end;
这篇关于你如何提取从TGraphicField位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文