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_27
{
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 i = -width / 2; i <= width / 2; i++)
{
g.Clear(Color.Gray); //
int j = Convert.ToInt32(i * (Convert.ToSingle(height) / Convert.ToSingle(width)));
Rectangle DestRect = new Rectangle(0, height / 2 -j, width, 2 * j);
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, " ");
}
}
}
}