2012-01-02 26 views
1

在拉伸模式的圖片框上繪製圖像,我通過使用函數獲取真實座標並繪製鼠標點擊事件來翻譯鼠標座標並繪製通過覆蓋繪圖事件並使用繪圖事件Graphics來映射圖像。 由於圖片框被設置爲伸展,我只能獲得一個小尺寸的圖像,當我嘗試使用picturebox.DrawtoBitmap功能保存圖像。額外部分用黑色填充。請幫助我。在C#winforms中保存圖片的尺寸模式=拉伸的圖片

+0

如果你知道如何把它畫成一個圖片框,那麼你知道如何把它畫成*任何*的位圖。 Graphics.ScaleTransform是你的朋友。 – 2012-01-02 14:12:09

回答

7

你可以試試這個:

using (Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, 
           pictureBox1.ClientSize.Height)) { 
    using (Graphics g = Graphics.FromImage(bmp)) { 
    g.DrawImage(yourBitmap, 
       new Rectangle(0, 0, bmp.Width, bmp.Height), 
       new Rectangle(0, 0, yourImage.Width, yourImage.Height), 
       GraphicsUnit.Pixel); 
    } 
    bmp.Save(@"c:\yourfile.png", ImageFormat.Png); 
}