现在的位置: 首页 > 综合 > 正文

No 81 · 以从上向下拉伸方式显示图像

2014年02月27日 ⁄ 综合 ⁄ 共 1330字 ⁄ 字号 评论关闭
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Ex13_25
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private Bitmap MyBitmap;
        private void button2_Click(object sender, EventArgs e)
        {
            //打开图像文件
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图像文件(JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPeg 图像文件(*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //得到原始大小的图像
                Bitmap SourceBitmap = new Bitmap(openFileDialog.FileName);
                //得到缩放后的图像
                MyBitmap = new Bitmap(SourceBitmap, this.pictureBox1.Width, this.pictureBox1.Height);
                this.pictureBox1.Image = MyBitmap;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //以从上向下拉伸方式显示图像
            try
            {
                int width = this.MyBitmap.Width; //图像宽度	
                int height = this.MyBitmap.Height; //图像高度
                Graphics g = this.panel1.CreateGraphics();
                g.Clear(Color.Gray); //初始为全灰色
                for (int y = 1; y <= height; y++)
                {
                    Bitmap bitmap=MyBitmap.Clone (new Rectangle(0,0,width ,y),System.Drawing .Imaging.PixelFormat .Format24bppRgb );
                    g.DrawImage (bitmap,0,0);
                    System.Threading.Thread.Sleep(10);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
        }
    }
}

 

【上篇】
【下篇】

抱歉!评论已关闭.