2009-08-23 69 views
0

作爲我之前提到的問題,我得到了我的區域,但花了最後兩個小時試圖顯示單獨拍攝該區域的小圖片;最終目標是能夠任意顯示我選擇的任意數量的圖像。 到目前爲止,這是我的代碼:如何在Picturebox中定義的區域內顯示圖像?

void OnPaintRadar(Object sender, PaintEventArgs e) 
{ 
    Graphics g = e.Graphics;   
    Bitmap blip = new Bitmap(tst_Graphics.Properties.Resources.dogtag); 
    Rectangle radar_rect = new Rectangle(myRadarBox.Left + 80, myRadarBox.Left + 7, myRadarBox.Width - 200, myRadarBox.Height + 200); 
    using (Pen drw_pen = new Pen(Color.White, 1)) 
    { 
     using (GraphicsPath path = new GraphicsPath()) 
     { 
      path.AddPie(radar_rect, 180, 180); 
      path.CloseFigure(); 
      using (Region rdRegion = new Region(path)) 
      { 
       g.DrawPath(drw_pen, path); 
       g.Clip = rdRegion; 
       PictureBox pb = new PictureBox(); 
       pb.Image = (blip); 
       pb.Size = blip.Size; 
       g.DrawImage(blip, radar_rect); 
      } 
     } 

    } 

}// end paint method 

我已經試過DrawImageUnscaled方法還,但我要麼得到我的小圖片吹填補了餡餅區域或不顯示任何內容。

回答

1

Click here運行示例應用程序,演示如何做雷達(或至少一種方式)的基礎知識。注意:此應用程序不會執行雙緩衝或微小圖像的透明度。

該項目的源代碼是here

+0

非常感謝。我會看看它,稍後再回復你。 – 2009-08-24 12:23:44

1

這條線:

pb.Image = (blip); 

是什麼引起微小的形象出現大。基本上,你從資源拉出一個微小的位圖,然後將PictureBox的Image屬性設置爲該位圖(我假設「pb」是窗體上的一個PictureBox)。嘗試評論該行及其下面的行。

+0

沒有快樂。事實上,我只是認爲,因爲我沒有使用圖片框,反正評論線不會影響任何東西,因爲我將圖片,而不是圖片框,添加到該地區。 – 2009-08-23 23:18:41

相關問題