缩略图浏览器

刚刚对着书打了个例子,用于把图片生成缩略图来浏览:

在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,"提示消息");
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值