procedure ChangPicSize(SourceFileName, DescFileName: string; X,Y:Integer);
var
jpg,SourceJpg: TJPEGImage;
bmp, SourceBmp, tmpbmp: TBitmap;
begin
if UpperCase(ExtractFileExt(SourceFileName)) = '.JPG' then
begin
bmp := TBitmap.Create;
SourceJpg := TJPEGImage.Create;
Jpg := TJPEGImage.Create;
try
try
//Load source file
SourceJpg.LoadFromFile(SourceFileName);
//Change file size
bmp.Width := X;
bmp.Height := Y;
bmp.PixelFormat := pf32bit;
bmp.Canvas.StretchDraw(Rect(0, 0, X, Y), SourceJpg);
//Save file
jpg.Assign(bmp);
jpg.SaveToFile(DescFileName);
except
end;
finally
bmp.Free;
jpg.Free;
SourceJpg.Free;
end;
end
else if UpperCase(ExtractFileExt(SourceFileName)) = '.BMP' then
begin
bmp := TBitmap.Create;
tmpbmp := TBitmap.Create;
SourceBmp := TBitmap.Create;
try
try
//Load File
SourceBmp.LoadFromFile(SourceFileName);
//Change file size
bmp.Width := X;
bmp.Height := Y;
bmp.PixelFormat := pf32bit;
bmp.Canvas.StretchDraw(Rect(0, 0, X, Y), SourceBmp);
//Save file
tmpbmp.Assign(bmp);
tmpbmp.SaveToFile(DescFileName);
except
end;
finally
bmp.Free;
tmpbmp.Free;
SourceBmp.Free;
end;
end;
end;
--------------------------------------------------
procedure TMainForm.ChangeImageFormate; //压缩
var Bitmap : TBitmap;
Zoom : Integer;
begin
Bitmap := TBitmap.Create; //1
try
with ImageCert do begin
Bitmap.Assign(Picture.Graphic); //2
Picture := nil; //3
Zoom := Max(Bitmap.Width div Width,Bitmap.Height div Height)+1; //4
Width := Bitmap.Width div Zoom; //5
Height := Bitmap.Height div Zoom; //6
Canvas.StretchDraw(Rect(0,0,Width,Height),Bitmap); //7
end;
finally
Bitmap.Free;
end;
end;
procedure TMainForm.RotateImage; //旋转
var x,y : Integer;
TmpBitMap : TBitmap;
begin
TmpBitMap := TBitmap.Create;
try
TmpBitMap.Assign(ImageCert.Picture.Graphic);
with ImageCert do begin
Picture.Bitmap.Height := TmpBitMap.Width;
Picture.Bitmap.Width := TmpBitMap.Height;
for x:=0 to Height do
for y:=0 to Width do
Canvas.Pixels[TmpBitMap.Height-x,y] := TmpBitMap.Canvas.Pixels[y,x];
Height := TmpBitMap.Width;
Width := TmpBitMap.Height;
end;
finally
TmpBitMap.Free;
end;
end;