delphi JPG转为BMP存入数据库
delphi JPG转为BMP存入数据库
必须在uses中引用JPEG
procedure TForm1.BitBtn3Click(Sender: TObject);
var
jpg:TJPEGimage;
bmp:Tbitmap;
ext:string;
begin
if openpicturedialog1.Execute then
begin
ext:=extractfileext(openpicturedialog1.FileName);//提取文件扩展名
if (ext='.bmp') or (ext ='.BMP') then
begin
image1.Picture.LoadFromFile(openpicturedialog1.FileName);
table1.Edit ;
table1.Fields[2].Assign(image1.Picture);
end
else if (ext='.JPG') or (ext='.jpg') or (ext='.jpeg') or (ext='.JPEG') then
begin
jpg:=TJPEGimage.Create;
bmp:=Tbitmap.Create;
try
jpg.LoadFromFile(openpicturedialog1.FileName);
bmp.Assign(jpg);
table1.Edit;
table1.Fields[2].Assign(bmp);
finally
jpg.Free ;
bmp.Free;
end;
end;
end;
end;
var
jpg:TJPEGimage;
bmp:Tbitmap;
ext:string;
begin
if openpicturedialog1.Execute then
begin
ext:=extractfileext(openpicturedialog1.FileName);//提取文件扩展名
if (ext='.bmp') or (ext ='.BMP') then
begin
image1.Picture.LoadFromFile(openpicturedialog1.FileName);
table1.Edit ;
table1.Fields[2].Assign(image1.Picture);
end
else if (ext='.JPG') or (ext='.jpg') or (ext='.jpeg') or (ext='.JPEG') then
begin
jpg:=TJPEGimage.Create;
bmp:=Tbitmap.Create;
try
jpg.LoadFromFile(openpicturedialog1.FileName);
bmp.Assign(jpg);
table1.Edit;
table1.Fields[2].Assign(bmp);
finally
jpg.Free ;
bmp.Free;
end;
end;
end;
end;
附加:
extractfilepath(application.exename)//获取可执行文件的完整路径
extractfilename(application.exename)//获取可执行文件的文件名
extractfileext(application.exename)//获取可执行文件的扩展名
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!