刚刚对着书打了个例子,用于把图片生成缩略图来浏览:
在form中添加一个Button就可以了!
现在我想把它改到我的网页中~~~
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
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,"提示消息");
}
}
}
}