你如何提取从TGraphicField位图?

编程入门 行业动态 更新时间:2024-10-28 07:34:39
本文介绍了你如何提取从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位图?

    本文发布于:2023-10-29 22:49:56,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1540996.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:位图   TGraphicField

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!