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);//將位圖數據區復制到新開辟的內存中

目的很簡單,就是把圖像的所有像素值拷貝到內存中;
因為如果每次都對圖像直接處理會很慢。
但是拷貝到內存中后,就會加快圖像處理的速度。
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM