C#中Rectangle(Point, Size) 和Rectangle(Int32, Int32, Int32, Int32) 区别

Rectangle(Point, Size) 从那个点Point开始,大小为size(width,height)的矩形。
Rectangle(Int32, Int32, Int32, Int32) 前两个int是开始点的x坐标,y坐标,后两个int是width,height。

例1:
using (Graphics g = this.CreateGraphics())
            {
                g.DrawRectangle(Pens.Red, 0, 0, 120, 120);
            }

例2:
Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
//定义一个矩形区域和图像的大小相同;
BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadWrite, bitmap.PixelFormat);
//以像素的格式锁定该图像,大小为rectangle,且模式为可读可写。

IntPtr intPtr = bitmapData.Scan0;//获得位图数据区首指针
int bytes = bitmap.Width * bitmap.Height * 3;//位图数据区大小(彩色图像,3个波段)
byte[] grayValues = new byte[bytes];//开辟内存,存储位图数据
Marshal.Copy(intPtr, grayValues, 0, bytes);//将位图数据区复制到新开辟的内存中

目的很简单,就是把图像的所有像素值拷贝到内存中;
因为如果每次都对图像直接处理会很慢。
但是拷贝到内存中后,就会加快图像处理的速度。
 
原文地址:https://www.cnblogs.com/muxiaoruo/p/2669058.html