Fdmemtable 内存表保存图片的例子

var
aStream: TMemoryStream;
LDataSet: TFDDataSet; // 申请一个FD数据集
MyStream: Tmemorystream;
MyJPEG: TJpegImage;
MyPng: TPngImage;
begin
inherited;
if img2.Picture.Graphic = nil then
begin
Application.MessageBox('没有图片可以增加!!', '提示', MB_OK + MB_ICONWARNING + MB_TOPMOST);

end
else
begin
aStream := TMemoryStream.Create();
MyStream := TMemoryStream.Create();
try
img2.Picture.SaveToStream(aStream);
fdmtPicture.Append;
fdmtPicture.FieldByName('p_picture_id').AsLargeInt := getSnowflake;
fdmtPicture.FieldByName('p_picture_guid').AsString := GetGUID;
fdmtPicture.FieldByName('p_products_id').AsLargeInt := aid;
fdmtPicture.FieldByName('p_picture_name').AsString := EditImageName.Text;
if img2.Picture.Graphic is TJPEGImage then
begin
MyJPEG := TJpegImage.Create;
MyJPEG.Assign(img2.Picture.Graphic);
MyJPEG.CompressionQuality := 10;
MyJPEG.Compress;
MyJPEG.SaveToStream(MyStream);
end;
if img2.Picture.Graphic is TPngImage then
begin
MyPng := TPngImage.Create;
MyPng.Assign(img2.Picture.Graphic);
MyPng.CompressionLevel := 9;
MyPng.SaveToStream(MyStream);
end;
MyStream.Position := 0;
TBlobField(fdmtPicture.FieldByName('p_picture_thumbnail')).LoadFromStream(MyStream);
aStream.Position := 0;
TBlobField(fdmtPicture.FieldByName('p_picture_image')).LoadFromStream(aStream);
fdmtPicture.Post;
img2.Picture.Graphic := nil;
finally
MyStream.free;
aStream.Free;
end;
end;

转自https://www.cnblogs.com/Thenext/p/16422021.html

posted @ 2024-08-15 18:07  沧江魅影  阅读(6)  评论(0编辑  收藏  举报