我正在研究一個簡單的繪畫應用程序。除了保存,我得到了一切工作。我正在做一個面板內的所有繪畫操作。我需要將它保存爲圖像。這個怎麼做?在繪畫應用程序c中保存圖像#
回答
使用此代碼
Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);//to create bmp of same size as panel
Rectangle rect=new Rectangle(0,0,panel1.Width,panel1.Height); //to set bounds to image
panel1.DrawToBitmap(bmp,rect); // drawing panel1 imgae into bmp of bounds of rect
bmp.Save("C:\\a.png", System.Drawing.Imaging.ImageFormat.Png); //save location and type
非常感謝,它的工作 – Kanishka 2011-05-20 10:04:39
事情是這樣的:
public void SaveAs()
{
SaveFileDialog diag = new SaveFileDialog();
DialogResult dr = diag.ShowDialog();
if (dr.Equals(DialogResult.OK))
{
string _filename = diag.FileName;
// filename not specified. Use FileName = ...
if (_filename == null || _filename.Length == 0)
throw new Exception("Unspecified file name");
// cannot override RO file
if (File.Exists(_filename)
&& (File.GetAttributes(_filename)
& FileAttributes.ReadOnly) != 0)
throw new Exception("File exists and is read-only!");
// check supported image formats
ImageFormat format = FormatFromExtension(_filename);
if (format == null)
throw new Exception("Unsupported image format");
// JPG images get special treatement
if (format.Equals(ImageFormat.Jpeg))
{
EncoderParameters oParams = new EncoderParameters(1);
oParams.Param[0] = new EncoderParameter(
System.Drawing.Imaging.Encoder.Quality, 100L);
ImageCodecInfo oCodecInfo = GetEncoderInfo("image/jpeg");
yourImage.Save(_filename, oCodecInfo, oParams);
}
else
yourImage.Save(_filename, format);
}
}
究竟在哪裏讀取面板中的數據?我正在做一個面板上的所有圖像相關的操作, – Kanishka 2011-05-20 09:11:13
如果你使用WPF,你可以在RenderTargetBitmap採取alook。它可以使任何視覺成位圖,然後就可以使用@danyogiaxs保存awnser
CNC中
我還發現this SO post 做同樣的的WinForms
我使用Windows窗體 – Kanishka 2011-05-20 09:11:35
- 1. 通過C#應用程序在MySQL中保存圖像
- 2. 在地鐵應用程序中將圖像繪製到畫布
- 3. Android應用程序在圖庫中保存和存儲圖像?
- 4. 如何將圖像保存在WPF應用程序在C#
- 5. 在Android中保存畫布在圖像上繪圖
- 6. 圖像保存到iPhone應用程序
- 7. 在Windows應用商店應用程序中保存圖像
- 8. 爲繪畫應用程序優化繪圖c#
- 9. C#應用程序保存
- 10. 在畫布中繪製並將其保存爲較大圖像
- 11. 使用背景圖像在畫布上繪圖並保存圖像
- 12. OpenGL ES:在像素繪畫應用程序中撤消
- 13. 使用c將地圖保存到地鐵應用程序中的圖像#
- 14. 在iOS應用程序中生成並保存圖像
- 15. 如何在我的應用程序中保存圖像(路徑)?
- 16. 在android中保存指紋圖像時應用程序停止
- 17. 在Android應用程序中添加許多保存的圖像
- 18. Android在應用程序上下文中保存圖像
- 19. 在應用程序中保存圖像 - android
- 20. 在PictureBox中保存繪製的圖像
- 21. 應用程序將多個圖像保存到圖庫中
- 22. HTML 5畫布繪圖應用程序不繪圖
- 23. 如何在objective-c iPhone應用程序中保存webcontent和圖像?
- 24. 在Visual C#中繪製應用程序#
- 25. 在iphone應用程序運行時保存圖像
- 26. 在運行期間從Flash應用程序保存圖像?
- 27. 如何在應用程序內保存圖像
- 28. 將圖像保存到應用程序目錄中StorageStorageDirectory
- 29. 回形針將不保存圖像中的Rails應用程序
- 30. 在localStorage中保存InkManager筆畫 - windows 8應用程序
你使用的是winforms還是wpf? – aL3891 2011-05-20 09:04:09