如何切割图像的一部分 (100分)

  • 主题发起人 主题发起人 chur
  • 开始时间 开始时间
C

chur

Unregistered / Unconfirmed
GUEST, unregistred user!
image1.canvas.Rectangle(0,0,image1.width,image1.Height);
for x3:=0 to x2-x1 do
begin
for y3:=0 to y2-y1 do
begin
image1.Canvas.Pixels[x3,y3]:=image2.Canvas.Pixels[x3+x1,y3+y1];
end;
我想切割图像image2的一部分形成图像image1,但是如果按上述方法切割出来,
image1的其余部分还会进入image1,而且是用空白填充,我不想要多余的部分。
本来我想用设置image1的大小来处理,但是行不通。各位,怎么办?
 
你在循环过后加上
image2.Height:=x3;
image2.Width:=y3;
这样不行么?
 
不用CopyRect? Draw? BitBlt?
 
你在循环过后加上
image2.Height:=x3;
image2.Width:=y3;
-----------不行!!!!!
CopyRect? Draw? BitBlt?
-----------我不太会用,
而且需要的是处理后图像的大小只是x3,y3,而没有其他部分,
好像CopyRect不行,而且这些我都不太熟悉……poor
 
CopyRect很好用,
只要定义了上下左右四个点,加几个参数就可以了,
你可以看看Help
 
var
bmp :TBitmap;
begin
bmp :=TBitmap.Create; //假设你需要截取的图象大小为100×100
bmp.Width :=100;
bmp.Height :=100;
BitBlt(bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,
image1.Picture.Bitmap.Canvas.Handle,x,y,SRCCOPY);//截取image1中从x,y开始的100×100的图象
//保存在bmp中
end;
 
我做过一个拼图游戏,给你发来,仔细看,有你需要的答案!
我给你复制了一段代码!
procedure weizhi();
var
h,w:integer;
arects,arectd:trect;
begin
//以下是拼图图象初始化
h:=trunc(form1.image17.height/4);
w:=trunc(form1.image17.width/4);
with form1 do
begin
arects:=rect(0,0,w,h);
arectd:=rect(0,0,image1.height,image1.width);
image1.canvas.copymode:=cmsrccopy;
image1.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(w,0,2*w,h);
arectd:=rect(0,0,image2.height,image2.width);
image2.canvas.copymode:=cmsrccopy;
image2.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(2*w,0,3*w,h);
arectd:=rect(0,0,image3.height,image3.width);
image3.canvas.copymode:=cmsrccopy;
image3.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(3*w,0,4*w,h);
arectd:=rect(0,0,image4.height,image4.width);
image4.canvas.copymode:=cmsrccopy;
image4.canvas.CopyRect(arectd,image17.canvas,arects); //以上是第一列

arects:=rect(0,h,w,2*h);
arectd:=rect(0,0,image1.height,image1.width);
image5.canvas.copymode:=cmsrccopy;
image5.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(w,h,2*w,2*h);
arectd:=rect(0,0,image6.height,image6.width);
image6.canvas.copymode:=cmsrccopy;
image6.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(2*w,h,3*w,2*h);
arectd:=rect(0,0,image7.height,image7.width);
image7.canvas.copymode:=cmsrccopy;
image7.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(3*w,h,4*w,2*h);
arectd:=rect(0,0,image8.height,image8.width);
image8.canvas.copymode:=cmsrccopy;
image8.canvas.CopyRect(arectd,image17.canvas,arects);//以上是第二列

arects:=rect(0,2*h,w,3*h);
arectd:=rect(0,0,image9.height,image9.width);
image9.canvas.copymode:=cmsrccopy;
image9.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(w,2*h,2*w,3*h);
arectd:=rect(0,0,image10.height,image10.width);
image10.canvas.copymode:=cmsrccopy;
image10.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(2*w,2*h,3*w,3*h);
arectd:=rect(0,0,image11.height,image11.width);
image11.canvas.copymode:=cmsrccopy;
image11.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(3*w,2*h,4*w,3*h);
arectd:=rect(0,0,image12.height,image12.width);
image12.canvas.copymode:=cmsrccopy;
image12.canvas.CopyRect(arectd,image17.canvas,arects); //以上是第三列

arects:=rect(0,3*h,w,4*h);
arectd:=rect(0,0,image13.height,image13.width);
image13.canvas.copymode:=cmsrccopy;
image13.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(w,3*h,2*w,4*h);
arectd:=rect(0,0,image14.height,image14.width);
image14.canvas.copymode:=cmsrccopy;
image14.canvas.CopyRect(arectd,image17.canvas,arects);

arects:=rect(2*w,3*h,3*w,4*h);
arectd:=rect(0,0,image15.height,image15.width);
image15.canvas.copymode:=cmsrccopy;
image15.canvas.CopyRect(arectd,image17.canvas,arects); // 以上是第四列

end;
注意我的来信: tianrei@21cn.com
盼答复!
 
我不知道你的邮箱!
 
Sorry, now I have no time to see it.
tomorrow I will do it.
thank you all.
chur@263.net
 
谢谢各位,可以解决了
 
后退
顶部