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_29
{
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 j = -height / 2; j <= height / 2; j++)
{
g.Clear(Color.Gray); //初始为全灰色
int i = Convert.ToInt32(j * (Convert.ToSingle(width) / Convert.ToSingle(height)));
Rectangle DestRect = new Rectangle(width / 2 - i, 0, 2 * i, height);
Rectangle SrcRect = new Rectangle(0, 0, MyBitmap.Width, MyBitmap.Height);
g.DrawImage(MyBitmap, DestRect, SrcRect, GraphicsUnit.Pixel);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示");
}
}
}
}
No 85 · 以左右翻转方式显示图像
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.