■■■■■■■■■■如何在Image中显示出位图的图象数据? ■■■■■■■■■■ (100分)

Y

ymf

Unregistered / Unconfirmed
GUEST, unregistred user!
我 的Access数据库“OLE 对象”字段中存放着一个位图数据(没有文件头信息,
一个象素=8 bit,图象高度和宽度信息在其它字段中),
请问如何将此图象在Image中显示出来?
 
????????????????????
 
没有头信息你怎么知道位图多宽多高,多少bit表示一个像素呀?
 
to Another_eYes
等我问一下啊
 
to Another_eYes

一个象素=8 bit,图象高度和宽度在其它字段中

 
那就很简单了。
(从数据库读出部分略, 假设读出后保存在buffer变量里)
type
TColorEntry = packed record
b, g, r, a: Byte;
end;

TBitmapInfo256 = record
bmiHeader: TBitmapInfoHeader;
ColorEntry: array [0..255] of TColorEntry;
end;

var
buffer: pointer;
hbmp: HBITMAP;
bmInfo: TBitmapInfo256;
begin
bmInfo.bmiHeader.biSize:=SizeOf(TBitmapInfoHeader);
bmInfo.bmiHeader.biPlanes:=1;
bmInfo.bmiHeader.biBitCount:=8;
bmInfo.bmiHeader.biCompression:=BI_RGB;
bmInfo.bmiHeader.biWidth:=adodataset1.fieldbyname('bmpwidth').asinteger;
bmInfo.bmiHeader.biHeight:=adodataset1.fieldbyname('bmpheight').asinteger;
hbmp := createDIBSection(0, bminfo, DIB_RGB_COLORS, buffer, 0, 0);
Image1.picture.bitmap.handle := hbmp;
end;
 
to Another_eYes
请问你如何把图象数据读到buffer中(不要笑我,我很菜的 ^-^),还有下面有的地方不懂请你解释一下
var
buffer: pointer;
hbmp: HBITMAP;//这是一个什么类型
bmInfo: TBitmapInfo256;
begin
bmInfo.bmiHeader.biSize:=SizeOf(TBitmapInfoHeader);
bmInfo.bmiHeader.biPlanes:=1;
bmInfo.bmiHeader.biBitCount:=8;
bmInfo.bmiHeader.biCompression:=BI_RGB;
bmInfo.bmiHeader.biWidth:=adodataset1.fieldbyname('bmpwidth').asinteger;
bmInfo.bmiHeader.biHeight:=adodataset1.fieldbyname('bmpheight').asinteger;
hbmp := createDIBSection(0, bminfo, DIB_RGB_COLORS, buffer, 0, 0);// 这里编译出错:Incompatible types: 'tagBITMAPINFO' and 'TBitmapInfo256'
Image1.picture.bitmap.handle := hbmp;
end;
 
to jsxjd
不行的
 
不好意思, 代码里忘了, 你强制类型转换一下就可以了。
hbmp := CreateDIBSection(0, PBitmapInfo(@bmInfo)^, DIB_RGB_COLORS, buffer, 0, 0);

从数据库读出(假设你用ado控件):
代码:
var
  stream: TADOBlobStream;
  buffer: Pointer;
begin
  stream := TADOBlobStream.Create(TBlobField(ADODataSet1.Fieldbyname('图像字段')), bmRead);
  getmem(buffer, stream.size);
  stream.Read(PChar(buffer)^, stream.size);
  stream.free;
end;
 
Another_eYes大虾,接受答案了,不过还要麻烦你一下,请看:
http://expert.csdn.net/Expert/topic/1176/1176496.xml?temp=.8184015
 
顶部