📄 从内存流中读取图片给数据库的i字段.txt
字号:
从内存流中读取图片给数据库的i字段
procedure TForm1.Button5Click(Sender: TObject);
//保存图像
var
strm: TMemoryStream;
ext: String;
begin
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件的扩展名
strm := tmemorystream.Create ;
try
image1.Picture.Graphic.SaveToStream(strm);
adotable1.Edit ;
strm.Position :=0;
tblobfield(adotable1.FieldByName('i')).LoadFromStream(strm);//提示bitmap is not valid// 请问该怎么改写 谢谢
//以下记录保存到数据库的图像格式
if (uppercase(ext) = '.BMP') then
adotable1.FieldByName('isbmp').Value := 1 //BMP型图像数据
else
if (uppercase(ext) = '.JPG') OR ( uppercase(ext) = '.JPEG') Then
adotable1.FieldByName('isbmp').Value := 0; //JPEG型图像数据
adotable1.Post ;
finally
strm.Free ;
Application.MessageBox('保存成功');
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -