有个image控件,加载了一个较大图片,并开了stretch=true
现在用Image1.Canvas.CopyRect截图,发现截下来的是缩小前的图片
我需要在缩放后的图上截图,该如何处理?

解决方案 »

  1.   

    i1为拉伸后的源图TImage
    i2为截图TImage
    var
      rc  : TRect;
    begin
      rc.Top := 0;
      rc.Left := 0;
      rc.Bottom := i1.Height;
      rc.Right := i1.Width;
      i2.Canvas.StretchDraw(rc, i1.Picture.Graphic);
    end;
      

  2.   

    CopyRect 图片会拉伸的,用BITBIT
      

  3.   


    var
      R, R1: TRect;
    begin
       R := Image1.BoundsRect;
       R1 := Image2.BoundsRect;
       Canvas.CopyRect(R1, Canvas, R);
    end;这样图片有点失真
      

  4.   

    把图片取下来按照image的尺寸重新画一下,这样尺寸就小了,然后再裁剪。
      

  5.   

    写个图像缩放函数吧,不必使用TImage做图像缩放。
      

  6.   

    我前几天也写过一个差不多的,你截取的是原图的一部分,image.stretch := true 后剪切得到的图片是按你image的大小显示的,要想按照截取前的大小显示,必须记录剪切前图片显示的缩放比例,然后在调整image的height和width。
      

  7.   

    你要先把图片缩小到你的image的大小,在进行截图
      

  8.   

    Function ChangeImageSize(gImage:TImage;SourceBmp:TBitmap;X,Y:Integer):Boolean;
    var
      iWidth,iHeight:Integer;
      TmpBmp:TBitmap;
    begin
      TmpBmp:=TBitmap.Create;
      iWidth:=SourceBmp.Width;
      iHeight:=SourceBmp.Height;
      if (Trunc((X / iWidth ) * iHeight) > Y) then
        begin
          TmpBmp.Width:=Trunc((iHeight / Y) * iWidth);
          TmpBmp.Height:=Y;
        end
      else
        begin
          TmpBmp.Width:=X;
          TmpBmp.Height:=Trunc((X / iWidth) * iHeight);
        end;
      TmpBmp.PixelFormat:=pf24bit;
      TmpBmp.Canvas.StretchDraw(Rect(0,0,TmpBmp.Width,TmpBmp.Height),SourceBmp);
      gImage.Picture.Bitmap.Assign(TmpBmp);
      TmpBmp.Free;
    end;我写的改变图像大小的函数  改变完大小后截取就是你想要的了
      

  9.   

    呵呵  上面谢的有点错误   TmpBmp.Width:=Trunc((iHeight / Y) * iWidth);  这句应该改为 TmpBmp.Width:=Trunc((Y / iHeight) * iWidth);