簡體   English   中英

如何將部分圖像插入圖片框?

[英]how to insert part of image into picturebox?

我不太確定是否可以將一部分圖像插入到圖片盒中,但是我想創建一個尺寸為500 * 500像素的圖像,然后通過將其設置為50 * 50的可連接的小片段來使用圖片在圖片框內的位置...

通過使用圖形,是否有可能實現類似的目的? 我不太熟悉...(我在談論C#表單應用程序...)

經過一段時間的搜索和很少的個人嘗試,我找到了解決方案,但這不是我自己的解決方案,但可惜的是我忘記了我從哪里來的:

   private static Image cropImage(Image img, Rectangle cropArea)
   {
       Bitmap bmpImage = new Bitmap(img);
       Bitmap bmpCrop = bmpImage.Clone(cropArea,
       bmpImage.PixelFormat);
       return (Image)(bmpCrop);
   }

這將創建裁剪的圖像,您現在可以在代碼中使用它。 樣品:

   Picturebox P = new Picturebox;
   P.BackgroundImage = cropImage(ImageThatWillBeCropped, new Rectangle(0,0,50,50));

如果有人發現此功能有用,並且需要矩形說明,請隨時提出:)

感謝您的良好回答。 最好是p.Image:

P.Image = cropImage(ImageThatBeCropped, new Rectangle(0, 0, 50,50));

以實際尺寸查看圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM