我们的类添加三个私有的数据成员:private Bitmap m_bitmap;private int m_width0;private int m_height0;在构造函数中初始化这三个数据成员,代码如下: public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // m_bitmap = null; m_width0 = m_pictureBox.Size.Width; m_height0 = m_pictureBox.Size.Height; }
bmp.Save("bbb.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=11392
// // TODO: Add any constructor code after InitializeComponent call // m_bitmap = null; m_width0 = m_pictureBox.Size.Width; m_height0 = m_pictureBox.Size.Height; }
private void m_btnSaveAs_Click(object sender, System.EventArgs e) { //创建一个保存对话框对象 SaveFileDialog sfd = new SaveFileDialog(); //设置对话框的各项属性 sfd.Title = "转化为"; sfd.OverwritePrompt = true; sfd.CheckPathExists = true; sfd.Filter = m_cmbSaveAs.Text + "|" + m_cmbSaveAs.Text; sfd.ShowHelp = true; if(sfd.ShowDialog() == DialogResult.OK) { //如果是OK,则根据不同的选项保存为相应格式的文件 string strFileName = sfd.FileName; switch(m_cmbSaveAs.Text) { case "*.bmp": // 在这里用ImageFormat类 m_bitmap.Save(strFileName, ImageFormat.Bmp); break; case "*.jpg": // 在这里用ImageFormat类 m_bitmap.Save(strFileName, ImageFormat.Jpeg); break; case "*.gif": // 在这里用ImageFormat类 m_bitmap.Save(strFileName, ImageFormat.Gif); break; case "*.tif": // 在这里用ImageFormat类 m_bitmap.Save(strFileName, ImageFormat.Tiff); break; } this.Text = "Image Converter: " + strFileName; } }