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 · 以左右翻轉方式顯示圖像
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.