缩放图片
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);