匿名用户
1级
2019-01-05 回答
private void button1_Click(object sender, EventArgs e)//打开一个图片
{
this.openFileDialog1.ShowDialog();
if (this.openFileDialog1.FileName == "")
{
MessageBox.Show("请选择一个文件");
return;
}
this.pictureBox1.Image = Bitmap.FromFile(this.openFileDialog1.FileName);
private void button2_Click(object sender, EventArgs e)//以另一种格式保存图片
{
this.saveFileDialog1.ShowDialog();
string name = this.saveFileDialog1.FileName;
if (this.saveFileDialog1.FileName == "")
{
MessageBox.Show("请选择一个文件");
}
MessageBox.Show(this.saveFileDialog1.FileName);
if (this.radioButton1.Checked)
{
this.pictureBox1.Image.Save(name + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
if (this.radioButton2.Checked)
{
this.pictureBox1.Image.Save(name + ".tif", System.Drawing.Imaging.ImageFormat.Tiff);
}
if (this.radioButton3.Checked)
{
this.pictureBox1.Image.Save(name + ".Gif", System.Drawing.Imaging.ImageFormat.Gif);
}
if (this.radioButton4.Checked)
{
this.pictureBox1.Image.Save(name + ".Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
} if (this.radioButton5.Checked)
{
this.pictureBox1.Image.Save(name + ".Png", System.Drawing.Imaging.ImageFormat.Png);
}
if (this.radioButton6.Checked)
{
this.pictureBox1.Image.Save(name + ".Wmf", System.Drawing.Imaging.ImageFormat.Wmf);
}
}