var
  Bitmap: TBitmap;
  MyRect, MyOther: TRect;
begin  MyRect := Rect(10,10,100,100);  MyOther := Rect(10,111,100, 201);
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('c:\windows\tartan.bmp');
 // Form1.Canvas.BrushCopy(MyRect, Bitmap, MyRect, clBlack);
  Form1.Canvas.CopyRect(MyOther,Bitmap.Canvas,MyRect);  Bitmap.Free;
end;我的问题:
1:我怎样知道相片文件的象素呢?(因为我要从其中件位置复制到右侧边上。)
2:Form1.Canvas.CopyRect(MyOther,Bitmap.Canvas,MyRect);的意思是说,从myrect大小的图片复制成MYOTHER大小的图片吗?
3:怎么用ASSIGN把图片保存呢?谢谢!!!

解决方案 »

  1.   

    从文件读取完毕之后,bitmap对象的Width和Height属性就标示了文件的纵横像素数。
    存盘的问题,可以考虑使用文件流TFileStream。
      

  2.   

    1:我怎样知道相片文件的象素呢?(因为我要从其中件位置复制到右侧边上。)
       问题描叙不清晰:
       要知道图片大小可以使用Bitmap.Width Bitmap.Height
       要知道具体某个像素的色彩值可以使用Bitmap.ScanLine[row]
       也可以使用Bitmap.Canvas.Pixels[x, y]2:Form1.Canvas.CopyRect(MyOther,Bitmap.Canvas,MyRect);的意思是说,从myrect大小的图片复制成MYOTHER大小的图片吗?
       是指把Bitmap.Canvas的MyRect区域的内容复制到MyOther,会进行相应的缩放,所以不是一定要进 行缩放处理,MyOther和MyRect的大小要一致(偏移可以不同)3.不明白问题的意思。保存成文件?在内存中保存???
      

  3.   

    Bitmap := TBitmap.Create;
      Bitmap.LoadFromFile('c:\a.bmp');
      h:=bitmap.Width div image1.Width;
      l:=bitmap.Height div image1.Height ;
      image2.Canvas.CopyRect(Rect(0,0,shape1.Width,shape1.height),bitmap.canvas,Rect((shape1.top-image1.top)*h,(shape1.left-image1.left)*l,shape1.Width*h ,shape1.Height*l));
      image2.Picture.SaveToFile('c:\b.jpg');为啥显示在IMAGE2中的图片总会必SHAPE1框住的部分少一点呢?
      

  4.   

    image2.Canvas.CopyRect(Rect(0,0,shape1.Width,shape1.height),bitmap.canvas,Rect((shape1.top-image1.top)*h,(shape1.left-image1.left)*l,shape1.Width*h ,shape1.Height*l));
    是不是应该:
    image2.Canvas.CopyRect(Rect(0,0,shape1.Width,shape1.height),bitmap.canvas,Rect((shape1.top-image1.top)*h,(shape1.left-image1.left)*l,(shape1.top-image1.top+shape1.Width)*h ,(shape1.left-image1.left+shape1.Height)*l));