using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace showPicture{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string pathname = string.Empty; //定义路径名变量 private void button1_Click(object sender, EventArgs e) //打开方法 { OpenFileDialog file = new OpenFileDialog(); file.InitialDirectory = '.'; file.Filter = '所有文件(*.*)|*.*'; file.ShowDialog(); if (file.FileName != string.Empty) { try { pathname = file.FileName; //获得文件的绝对路径 this.pictureBox1.Load(pathname); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void button2_Click(object sender, EventArgs e) //保存方法 { SaveFileDialog save = new SaveFileDialog(); save.ShowDialog(); if (save.FileName != string.Empty) { pictureBox1.Image.Save(save.FileName); } } }} |
|
来自: goodwangLib > 《C#图像》