簡單的影像處理,分別是放大兩倍、縮小兩倍以及形變旋轉
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 放大縮小形變
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = @"D:\MyPhoto\";
if (open.ShowDialog() == DialogResult.OK)
{
ImageForm MyImage = new ImageForm(open.FileName);
MyImage.Show();
}
}
class ImageForm : Form
{
Image image;
public ImageForm(String Filename)
{
image = Image.FromFile(Filename);
this.Text = Filename;
}
protected override void OnPaint(PaintEventArgs e)
{ /*放大2倍程式碼
this.Height = image.Height*2;
this.Width = image.Width*2;
e.Graphics.DrawImage(image,new Point[]{new Point(0,0),new Point(image.Width*2,0),new Point(0,image.Height*2)});
縮小2倍程式碼
this.Height = image.Height/2;
this.Width = image.Width/2;
e.Graphics.DrawImage(image,new Point[]{new Point(0,0),new Point(image.Width/2,0),new Point(0,image.Height/2)});
*/
//形變程式碼
this.Height=image.Height;
this.Width=image.Width;
e.Graphics.DrawImage(image,new Point[]{new Point(image.Width/2,0),new Point(image.Width,image.Height/2),new Point(0,image.Height/2)});
}
}
}
}
沒有留言:
張貼留言