C#影像處理(4):映像的剪裁

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   檔案   for   ar   

映像的剪裁方法,從中間剪裁返回剪裁後的左右兩頁,方法實現如下:

 1         /// <summary> 2         /// 圖片裁剪,返回左右兩頁 3         /// </summary> 4         /// <param name="Img">圖片</param> 5         /// <param name="RightMargin">從中間剪裁時左邊圖片向右位移量</param> 6         /// <param name="LeftMargin">從中間剪裁時右邊圖片向左位移量</param> 7         /// <returns>Dictionary</returns> 8         public Dictionary<string, Bitmap> ImgDiv(Image Img, int RightMargin, int LeftMargin) 9         {10             Dictionary<string, Bitmap> DictImg = new Dictionary<string, Bitmap>();11             //擷取圖片寬高12             int Width = Img.Width;13             int Height = Img.Height;14             //擷取圖片水平和垂直的解析度15             float dpiX = Img.HorizontalResolution;16             float dpiY = Img.VerticalResolution;17             //建立一個位元影像檔案18             Bitmap BitmapResult = new Bitmap((Width / 2) + RightMargin, Height, PixelFormat.Format24bppRgb);19             //設定位元影像檔案的水平和垂直解析度  與Img一致20             BitmapResult.SetResolution(dpiX, dpiY);21             //在位元影像檔案上填充一個矩形框22             Graphics Grp = Graphics.FromImage(BitmapResult);23             System.Drawing.Rectangle Rec = new System.Drawing.Rectangle(0, 0, (Width / 2) + RightMargin, Height);24             Grp.DrawImage(Img, 0, 0, Rec, GraphicsUnit.Pixel);25             //返回位元影像檔案26             Grp.Dispose();27             //擷取左邊映像28             DictImg["Left"] = BitmapResult;29             //在位元影像檔案上填充一個矩形框30             Bitmap BitmapRight = new Bitmap((Width / 2) + LeftMargin, Height, PixelFormat.Format24bppRgb);31             BitmapRight.SetResolution(dpiX, dpiY);32             Graphics GrpRight = Graphics.FromImage(BitmapRight);33             System.Drawing.Rectangle RecRight = new System.Drawing.Rectangle((Width / 2) - LeftMargin, 0, (Width / 2) + LeftMargin, Height);34             GrpRight.DrawImage(Img, 0, 0, RecRight, GraphicsUnit.Pixel);35             //擷取右邊映像36             DictImg["Right"] = BitmapRight;37             GrpRight.Dispose();38             GC.Collect();39             //返回位元影像檔案40             return DictImg;41         }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.