using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Ex13_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Bitmap MyBitmap; private void button1_Click(object sender, EventArgs e) { try { this.Refresh(); //打开图像文件 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "图像文件(JPeg, Gif)|*.jpg;*.jpeg;*.gif;| JPeg 图像文件(*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif"; if (openFileDialog.ShowDialog() == DialogResult.OK) { //得到原始大小的图像 MyBitmap = new Bitmap(openFileDialog.FileName); } int width = 0, height = 0; if (MyBitmap.Width > MyBitmap.Height) { width = 50; height = Convert.ToInt32(Convert.ToSingle(MyBitmap.Height) / Convert.ToSingle(MyBitmap.Width)) * 50; } else { height = 50; width = Convert.ToInt32(Convert.ToSingle(MyBitmap.Width) / Convert.ToSingle(MyBitmap.Height)) * 50; } Image thumbnail = MyBitmap.GetThumbnailImage(width, height, null, IntPtr.Zero); Graphics g = this.CreateGraphics(); g.DrawImage(thumbnail, 10, 10); g.DrawString(openFileDialog.FileName, new Font("宋体", 10f), Brushes.Black, 10, height + 20); g.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示信息"); } } private void Form1_Load(object sender, EventArgs e) { } } }