delphi 中怎样打开jpg图片,保存到数据库中并要打印
1个回答
展开全部
jpg:TJpegImage;
temp:string;
sum:string;
i,j:integer;
jj,bb:boolean;beginif openpicturedialog1.Execute thenbeginedit1.Text:=openpicturedialog1.FileName;
bmp:=TBitmap.create;
jj:= AnsiEndsText('.jpg',edit1.Text);//看看是jpg文件还是bmp文件
bb:= AnsiEndsText('.bmp',edit1.Text);if jj thenbeginJpg:=TJpegImage.Create;
Jpg.LoadFromFile(openpicturedialog1.FileName);
bmp.assign(jpg);jpg.free;key:=extractfilename(edit1.Text);//将jpg转化bmpsum:=key;i:=length(sum);i:=i-4;temp:='';for j:=1 to i dobegintemp:=temp+sum[j];end;key:=temp;key:=key+'.bmp';
bmp.savetofile(key);//转化结束,因为mysql不能存jpgbiao:=1;endelse if bb thenbeginbmp.LoadFromFile(openpicturedialog1.FileName);
key:=extractfilename(edit1.Text);biao:=0;end;image1.Picture.LoadFromFile(openpicturedialog1.FileName);bmp.free;end;保存图片:varPicture1:TPicture;begin// 保存图片到数据库中
Picture1:=TPicture.create;trytryif fileexists(edit1.text) then
with ADOtable1 dobeginadotable1.Close;
adotable1.Open;
Picture1.LoadFromFile(key);
if Locate('name',extractfilename(edit1.text),[loCaseInsensitive])=false thenbeginindexfieldnames:='name';
ADOtable1.Insert;
Fields[0].AsString:=extractfilename(key);
Fields[1].Assign(Picture1);Post;showmessage('图象保存成功!');endelseshowmessage('图象已经存在!');end;finallyPicture1.Free;bmp1.Free;end;exceptshowmessage('图象保存失败!');end;if biao=1 then
DeleteFile(key);end;打印则qreport中的qrimage,或者是fastrepot exports中的frBMPExport和frJPEGExport!!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询