怎样把image1的图片中被shape1选中的区域复制到一个image2中 ???

weidaqing 2008-10-29 03:19:50
怎样把image1的图片中被shape1选中的区域复制到一个image2中 ???


MyRect := Shape1.ClientRect;//定义复制范围
Bitmap := TBitmap.Create; //生成Bitmap对象
Bitmap.Assign(Image1.Picture);
Image2.Canvas.BrushCopy(MyRect, Bitmap, MyRect, clBlack); //将图片复制到Image2中
Bitmap.Free;

这样复制出来的图象总不是shape1选中的??
...全文
149 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
weidaqing 2008-10-29
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap: TBitmap;
MyRect : TRect;
P,p2:tPOINT;
begin
Image1.autosize:=true;
P := Image1.ScreenToClient(SHAPE1.ClientToScreen(P)); //把shape1的坐标转化为相对于Image1的坐标
P2.X :=p.x+SHAPE1.Width ;
p2.Y :=p.Y+ SHAPE1.Height ;//p2为右小角相对于Image1的坐标
MyRect :=rect(p.x,p.Y,p2.x,p2.y) ;
Bitmap := TBitmap.Create; //生成Bitmap对象
Bitmap.Assign(Image1.Picture.Graphic );
Image2.Canvas.BrushCopy(MyRect, Bitmap, MyRect, clBlack); //将图片复制到Image2中
Bitmap.Free;
end;

此办法存在的缺点就是:当Image1中的图片宽度大于Image1的宽度,而Image1.autosize:=false,此时复制的区域与你想得到的区域不一侄.

再此谢谢楼上的热情解答!
yyp629 2008-10-29
  • 打赏
  • 举报
回复
var
bmp: TBitmap;
pic: TPicture;
begin
bmp := TBitmap.Create;
// PICTURE OR METAFILE
if (ClipBoard.HasFormat(CF_PICTURE)) or
(ClipBoard.HasFormat(CF_METAFILEPICT)) then
begin
pic := TPicture.Create;
pic.Assign(ClipBoard);
X := pic.Width;
Y := pic.Height;
bmp.Width := X;
bmp.Height := Y;
bmp.Canvas.Draw(0, 0, pic.Graphic);
pic.Free;
end;
// BITMAP
if (ClipBoard.HasFormat(CF_BITMAP)) then
begin
bmp.Assign(ClipBoard);
end;
// Bitmap, picture or metafile is now in bmp
// When used free bmp!
end;
mdejtod 2008-10-29
  • 打赏
  • 举报
回复
MyRect := Shape1.ClientRect;//定义复制范围
关键是这个 MyRect
它不是有 x,y,width,heigth 嘛?改一下坐标不就行了
weidaqing 2008-10-29
  • 打赏
  • 举报
回复
这样只能复制image1左上角的区域,而被shape1选中的区域更本没被复制!
mdejtod 2008-10-29
  • 打赏
  • 举报
回复
var bmp : TBitmap;
MyRect : Windows.TRect;
begin
MyRect := Shape1.ClientRect;//定义复制范围
bmp := TBitmap.Create;
bmp.Width := img1.Width;
bmp.Height := img1.Height;
bmp.Canvas.CopyRect(MyRect,img1.Canvas,MyRect);
//再用 bitblt 画出来
end;

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧