GDI+实例开源,操作不是很熟练的朋友可以看一下。
本来是学c#的,但是由于喜欢web开发,所以winform学的不是怎么样,对python一直是知道理论也没有什么实践,最近找了点资料,做了点东西,和大家分享分享,有什么地方做的不好,还希望大家指点……
谢谢……
开发工具:visual studio 2005
Form1.cs页面:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication6
{
public partial class Form1 : Form
{
private Bitmap smallBmp;
private Bitmap bmp; //holds original loaded image
private Bitmap newbmp; //holds latest version of image
private bool imageStatus = false; //indicates image is loaded
private int resizeLevel; //level image magnified/reduced
private Point lastPoint = Point.Empty;//tracks mouse movement
private Point origPoint = Point.Empty;//mouse down coordinates
private Rectangle rectSel;//select area
private bool selectStatus;//true if area selected
public Form1()
{
InitializeComponent();
panel1.MouseDown+=new MouseEventHandler(panel1_MouseDown);
panel1.MouseUp+=new MouseEventHandler(panel1_MouseUp);
panel1.MouseMove+=new MouseEventHandler(panel1_MouseMove);
panel1.Paint+=new PaintEventHandler(panel1_Paint);
}
private void mirrorMenuItem_Click(object sender, EventArgs e)
{
Graphics g = panel1.CreateGraphics();
int h = newbmp.Height;
int w = newbmp.Width;
Point[] destPts ={
new Point(w,0),
new Point(0,0),
new Point(w,h)
};
Bitmap tempBmp = new Bitmap(w, h);
Graphics gr = Graphics.FromImage(tempBmp);
gr.DrawImage(newbmp, destPts);
g.DrawImage(tempBmp, 0, 0);
newbmp = tempBmp;
g.Dispose();
gr.Dispose();
}