高手请进:image缩放后,截取图像的问题 有个image控件,加载了一个较大图片,并开了stretch=true现在用Image1.Canvas.CopyRect截图,发现截下来的是缩小前的图片我需要在缩放后的图上截图,该如何处理? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 i1为拉伸后的源图TImagei2为截图TImagevar 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; CopyRect 图片会拉伸的,用BITBIT var R, R1: TRect;begin R := Image1.BoundsRect; R1 := Image2.BoundsRect; Canvas.CopyRect(R1, Canvas, R);end;这样图片有点失真 把图片取下来按照image的尺寸重新画一下,这样尺寸就小了,然后再裁剪。 写个图像缩放函数吧,不必使用TImage做图像缩放。 我前几天也写过一个差不多的,你截取的是原图的一部分,image.stretch := true 后剪切得到的图片是按你image的大小显示的,要想按照截取前的大小显示,必须记录剪切前图片显示的缩放比例,然后在调整image的height和width。 你要先把图片缩小到你的image的大小,在进行截图 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;我写的改变图像大小的函数 改变完大小后截取就是你想要的了 呵呵 上面谢的有点错误 TmpBmp.Width:=Trunc((iHeight / Y) * iWidth); 这句应该改为 TmpBmp.Width:=Trunc((Y / iHeight) * iWidth); delphi 如何将image中的图片写入到access数据库中,并且能读取出来。 怎样在动态创建的窗体上动态创建图片控件 请问如何在DELPHI里检测系统是否安装了adobe reader ~~~~有关DPI的问题~~~~急~~ 求救:如何在低配置机器里运行相应DelphiX程序?(因为占用的CPU相当高) 标题列排请问 delphi论坛01月专家榜 网络游戏应该作两层构架还是三层构架? 请教:在dbgrid中是否可固定某一列 SQL连接(金太阳) 成都:收购二手Delphi书.(含bpl,dll.数据库等) 两个窗口如何传递?
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;
var
R, R1: TRect;
begin
R := Image1.BoundsRect;
R1 := Image2.BoundsRect;
Canvas.CopyRect(R1, Canvas, R);
end;这样图片有点失真
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;我写的改变图像大小的函数 改变完大小后截取就是你想要的了