以下可以假设数据库表DB_Pic中有一字段为图形)
uses Jpeg;
procedure Tform1.Db_Addpic(sender:Tobject);
var
PicName,Ext:string;
JpegImage:TJpegImage;
begin
if openpicturedialog1.execute then
begin
DB_PIC.append;
PicName:=openpictureDialog1.Filename;
Ext:=ExtractFileExt(PicName);
if UpperCase(ExtName)='.BMP' then
begin
//直接存入数据库
end
else if (UpperCase(ExtName)='.JPG') or (UpperCase(ExtName)='.JPEG') then
begin
JPEgImage:=TJpegImage.create;
try
JpegImage.LoadfromFile(PicName);
DB_PIC.Picture.Graphic.Assign(JpegImage);
DB_Pic.Post;
Finally
JpegImage.free;
end;
end;
end;
end;