http://www.nssoft.net/showdoc.asp?did=178 function Jpg2Bmp(Jpg: TJpegImage): TBitmap; begin Result := nil; if Assigned(Jpg) then begin Result := TBitmap.Create; Jpg.DIBNeeded; {Key method...} Result.Assign(Jpg); {Its all folks...} end; end;
function Bmp2JPG(BmpFileName,JPGFileName:string;CompressRate:integer=86):boolean; 將BMP圖檔轉為JPG圖檔,BMP檔名為BmpFileName,JPG檔名為JPGFileName,CompressRate為JPG圖檔的壓縮率,若不傳入此參數內定為86%壓縮率.function JPG2BMP(JPGFileName,BmpFileName:string):boolean; 將JPG圖檔轉為BMP圖檔,JPG檔名為JPGFileName,BMP檔名為BmpFileNamefunction Bmp2JPG(BmpFileName,JPGFileName:string;CompressRate:integer=86):boolean; var jpg:TJPEGImage; bmp:tBitMap; begin jpg:=TJPEGImage.create; bmp:=TBitMap.create; result:=true; try bmp.LoadFromFile(BmpFileName); jpg.assign(bmp); jpg.CompressionQuality:=CompressRate; jpg.SaveToFile(JPGFileName); except result:=false; end; jpg.free; bmp.free; end; function JPG2BMP(JPGFileName,BmpFileName:string):boolean; var jpg:TJPEGImage; bmp:tBitMap; begin jpg:=TJPEGImage.create; bmp:=TBitMap.create; result:=true; try jpg.loadfromfile(JPGFileName); bmp.assign(jpg); bmp.SaveToFile(BmpFileName); except result:=false; end; jpg.free; bmp.free; end;
function Jpg2Bmp(Jpg: TJpegImage): TBitmap; begin Result := nil; if Assigned(Jpg) then begin Result := TBitmap.Create; Jpg.DIBNeeded; {Key method...} Result.Assign(Jpg); {Its all folks...} end; end;
將BMP圖檔轉為JPG圖檔,BMP檔名為BmpFileName,JPG檔名為JPGFileName,CompressRate為JPG圖檔的壓縮率,若不傳入此參數內定為86%壓縮率.function JPG2BMP(JPGFileName,BmpFileName:string):boolean;
將JPG圖檔轉為BMP圖檔,JPG檔名為JPGFileName,BMP檔名為BmpFileNamefunction Bmp2JPG(BmpFileName,JPGFileName:string;CompressRate:integer=86):boolean;
var jpg:TJPEGImage;
bmp:tBitMap;
begin
jpg:=TJPEGImage.create;
bmp:=TBitMap.create;
result:=true;
try
bmp.LoadFromFile(BmpFileName);
jpg.assign(bmp);
jpg.CompressionQuality:=CompressRate;
jpg.SaveToFile(JPGFileName);
except
result:=false;
end;
jpg.free;
bmp.free;
end;
function JPG2BMP(JPGFileName,BmpFileName:string):boolean;
var jpg:TJPEGImage;
bmp:tBitMap;
begin
jpg:=TJPEGImage.create;
bmp:=TBitMap.create;
result:=true;
try
jpg.loadfromfile(JPGFileName);
bmp.assign(jpg);
bmp.SaveToFile(BmpFileName);
except
result:=false;
end;
jpg.free;
bmp.free;
end;