添加jpeg单元
implementation
var
jpg:Tjpegimage; //用来存储jpg文件
bmp:Tbitmap; //用来存储bmp文件
pach:string;
打开图片按钮:
procedure TForm1.Button1Click(Sender: TObject);
begin
jpg:=Tjpegimage.Create();
bmp:=Tbitmap.Create();
if(openpicturedialog1.execute=true) then //如果打开成功
begin
pach:=openpicturedialog1.fileName;
image1.picture.loadFromfile(pach);
end
end;
转换按钮:
procedure TForm1.Button2Click(Sender: TObject);
begin
if(savepicturedialog1.Execute=true) then
begin
if(lowerCase(extractfileExt(pach))='bmp') then //如果打开毕业论文 的是bmp文件
begin /////bmp转jpg/////
bmp.loadFromfile(pach);
jpg.width:=bmp.width;
jpg.height:=bmp.height;
jpg.assign(bmp); //转换
jpg.saveTofile(savePictureDialog1.fileName);
end;
//*********************************************//
if(lowerCase(extractfileExt(pach))='jpg') then //如果打开的是jpg文件
begin /////jpg转bmp/////
jpg.loadFromfile(pach);
bmp.width:=jpg.width;
bmp.height:=jpg.height;
bmp.assign(jpg);
bmp.saveTofile(savePictureDialog1.fileName);
end;
jpg.free();
bmp.free();
end
错误信息:
Build
[Error] Unit1.pas(70): ';' expected but '.' found
[Error] Unit1.pas(76): Declaration expected but end of file found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
此过程最后一行加end if(lowerCase(extractfileExt(pach))='bmp') then
这句不对,扩展名包括“.”,应该是:if(lowerCase(extractfileExt(pach))='.bmp') then