How to use CopyRect method in Delphi

后端 未结 1 1977
[愿得一人]
[愿得一人] 2021-01-12 19:51

I\'m loading an image from disk and want to copy (part of) it to a second TImage:

Image1.Picture.LoadFromFile(S);
with Image1.Picture.Bitmap do
  Image2.Ca         


        
相关标签:
1条回答
  • 2021-01-12 20:49

    TCanvas.CopyRect copies the rectangle by using StretchBlt. StretchBlt requires a bitmap. If you're loading any other graphic type to your image then its Picture.Bitmap is empty. In fact the bitmap gets created just when you refer to it: with Image1.Picture.Bitmap do.

    You can use a temporary bitmap for the cause:

    var
      Bmp: TBitmap;
    begin
      Image1.Picture.LoadFromFile(S);
    
      Bmp := TBitmap.Create;
      try
        Bmp.Assign(Image1.Picture.Graphic);
    
        with Bmp do
          Image2.Canvas.CopyRect(Image2.Canvas.ClipRect, Canvas, Canvas.ClipRect);
      finally
        Bmp.Free;
      ..
    
    0 讨论(0)
提交回复
热议问题