代码压缩旋转图片

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;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值