iT邦幫忙

0

c# 影像處理-從一張大圖中抓取部分圖片內容顯示的方法

請問如果在一個PictureBox 控制項中載入一張大圖,
那麼如何擷取PictureBox 部分的區域到另一個PictureBox2 控制項中呢?

例如PictureBox 是900*900,而PictureBox2 只會顯示從位置x=200,y=100的地方開始抓起,
並抓出300*300的大小圖出來顯示?

外獅佬 iT邦大師 1 級 ‧ 2014-10-03 01:04:59 檢舉
這問題跟Picturebox無關
你要做的是...讀取原始的圖檔
然後從這個圖檔,擷取你要的區塊...
private static Image cropImage(Image img, Rectangle cropArea)
{
   Bitmap bmpImage = new Bitmap(img);
   return bmpImage.Clone(cropArea, bmpImage.PixelFormat);
}
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
丹尼爾
iT邦研究生 2 級 ‧ 2014-10-07 12:05:48
最佳解答

StartPiont = (200, 100)
CutArea = (0,0,300,300)

<pre class="c" name="code">
private Image CutImage(Image SourceImage, Point StartPoint, Rectangle CutArea)
{
    Bitmap NewBitmap = new Bitmap(CutArea.Width, CutArea.Height);
    Graphics tmpGraph = Graphics.FromImage(NewBitmap);
    tmpGraph.DrawImage(SourceImage, CutArea, StartPoint.X, StartPoint.Y, CutArea.Width, CutArea.Height, GraphicsUnit.Pixel);
    tmpGraph.Dispose();
    return NewBitmap;
}

我要發表回答

立即登入回答