游子日月长

笑渐不闻声渐悄,多情却被无情恼!

导航

缩放图片

function TFrmSelectPosImage.ResizeImage(var SrcImage: TImage; Scale: Integer = 1): TImage; // 缩放图片
var
  DstImage: TBitMap;
  Rect: TRect;
  DstWidth, DstHeight: Integer;
begin
  with SrcImage do
  begin
    DstWidth := SrcImage.Width div Scale;
    DstHeight := SrcImage.Height div Scale;
  end;

  try
    DstImage := TBitMap.Create;

    with DstImage do
    begin
      Width := DstWidth;
      Height := DstHeight;
      PixelFormat := pf32bit;
      Rect.TopLeft := Point(0, 0);
      Rect.BottomRight := Point(DstWidth, DstHeight);
      Canvas.Rectangle(0, 0, Width, Height);
      Canvas.StretchDraw(Rect, TGraphic(SrcImage.Picture.Bitmap));
    end;

    SrcImage.Picture.Bitmap.Assign(DstImage);
    SrcImage.Update;

    Result := SrcImage;
  finally
    FreeAndNil(DstImage);
  end;
end;

调用:
ImBodyItemPicture := ResizeImage(PicImage, 2);

 

posted on 2017-01-21 15:44  游子日月长  阅读(89)  评论(0编辑  收藏  举报