procedure TForm1.Button1Click(Sender: TObject);
var
Bmp1:TBitmap;
mystm:TBlobStream;
begin
try
if listbox1.ItemIndex <> -1 and 0 then
begin
query1.Close ;
query1.SQL.Clear ;
query1.SQL.Add('select graphic from picture where Name =:name_id ');
query1.Params.ParamByName('name_id').Value := listbox1.Items[listbox1.ItemIndex] ;
query1.Prepare ;
query1.Open;
mystm:=TBlobStream.Create(TGraphicfield(query1.FieldByName('graphic')),Bmread);
if mystm.Size > 0 then
begin
Bmp1:=Tbitmap.Create ;
Bmp1.LoadFromStream(mystm);
Image1.Picture.Assign(Bmp1);
end
else
Image1.Picture:=nil;
query1.Free ;
showmessage('ok!');
end
else
showmessage('请选择表格');
finally
bmp1.Free ;
end;
end;
上面这段代码,错误提示为bitmap为无效的格式。
能够高手指点一下,错在那里?
另外关于image,picture,graphic,bitmap,之类之间的关系,在使用的时候要注意一些什么冬冬,和stream结合的时候有要区别注意那些?盼回复!
var
Bmp1:TBitmap;
mystm:TBlobStream;
begin
try
if listbox1.ItemIndex <> -1 and 0 then
begin
query1.Close ;
query1.SQL.Clear ;
query1.SQL.Add('select graphic from picture where Name =:name_id ');
query1.Params.ParamByName('name_id').Value := listbox1.Items[listbox1.ItemIndex] ;
query1.Prepare ;
query1.Open;
mystm:=TBlobStream.Create(TGraphicfield(query1.FieldByName('graphic')),Bmread);
if mystm.Size > 0 then
begin
Bmp1:=Tbitmap.Create ;
Bmp1.LoadFromStream(mystm);
Image1.Picture.Assign(Bmp1);
end
else
Image1.Picture:=nil;
query1.Free ;
showmessage('ok!');
end
else
showmessage('请选择表格');
finally
bmp1.Free ;
end;
end;
上面这段代码,错误提示为bitmap为无效的格式。
能够高手指点一下,错在那里?
另外关于image,picture,graphic,bitmap,之类之间的关系,在使用的时候要注意一些什么冬冬,和stream结合的时候有要区别注意那些?盼回复!
procedure TForm1.Button1Click(Sender: TObject);
var
MStr:TMemoryStream;
beginMStr:=TMemoryStream.Create ;
Image1.Picture.Graphic.SaveToStream(MStr);
MStr.Position :=0;
Table1.Edit;
TBlobField(Table1.FieldByName('Image')).LoadFromStream(MStr);
Table1.Post ;
MStr.Free ;
Image1.Repaint ;
end;读取Bmp
procedure TForm1.Button2Click(Sender: TObject);
var
MS: TStream;
begin
with Table1 do
MS:=CreateBlobStream(FieldbyName('image'),bmRead);
if MS<>nil then
begin
Image2.Picture.Bitmap.LoadFromStream (MS); image2.Refresh ;
MS.Free;
end
else
ShowMessage('Ms is Null');end;