如何得到图片的某一矩形区域?(30分)

  • 主题发起人 主题发起人 wy0311
  • 开始时间 开始时间
怎么做呢?
比如:var bmp:tbitmap;
如何才能让bmp:=d:/abc.bmp中10,10到50,50的这个区域
请给几句代码,谢谢
 
procedure TForm1.BitBtn1Click(Sender: TObject);
var
vr1:trect;
begin
vr1:=rect(10,10,100,100);
form1.Image1.Canvas.CopyRect(vr1,image1.Canvas,vr1);
form1.Image2.Canvas.copyrect(vr1,image1.Canvas,vr1);
end;
注意:只支持位图的裁减
 
也可以用API:
BOOL BitBlt(

HDC hdcDest, // handle to destination device context
int nXDest, // x-coordinate of destination rectangle's upper-left corner
int nYDest, // y-coordinate of destination rectangle's upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source device context
int nXSrc, // x-coordinate of source rectangle's upper-left corner
int nYSrc, // y-coordinate of source rectangle's upper-left corner
DWORD dwRop // raster operation code
);
 
Copies part of an image from another canvas into the canvas.

procedure CopyRect(const Dest: TRect; Canvas: TCanvas; const Source: TRect);

Description

Use CopyRect to transfer part of the image on another canvas to the image of the TCanvas object. Dest specifies the rectangle on the canvas where the source image will be copied. The Canvas parameter specifies the canvas with the source image. Source specifies a rectangle bounding the portion of the source canvas that will be copied.

The portion of the source canvas is copied using the mode specified by CopyMode.

==========================
The following code illustrates the differences between CopyRect and BrushCopy. The bitmap graphic TARTAN.BMP is loaded into Bitmap and displayed on the Canvas of Form1. BrushCopy replaces the color black in the graphic with the brush of the canvas, while CopyRect leaves the colors intact.

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;
 
多人接受答案了。
 
后退
顶部