C# graphicspath 翻转
2011-05-05 14:42
141 查看
C#中GraphicsPath旋转问题(发现网上与此相关的资料很少,我是从一个英文网站上找到的方法,具体原理还不是很明白,写出来大家分享一下)
准备:新建一窗体,添加一个PictureBox和一个btn
功能:点击btn实现图像翻转
备注:我用的是png格式的图
代码:
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 pathflip
{
public partial class Form1 : Form
{
private GraphicsPath path;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Image image = this.pictureBox1.Image;
image.RotateFlip(RotateFlipType.Rotate180FlipY);
this.pictureBox1.Image = image;
Matrix matrix = new Matrix(-1, 0, 0, 1, image.Width, 0);
this.path.Transform(matrix);
this.pictureBox1.Region = new Region(this.path);
}
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmp = (Bitmap)this.pictureBox1.Image;
this.path = this.CalculateGrahicsPath(bmp);
this.pictureBox1.Region = new Region(this.path);
}
private GraphicsPath CalculateGrahicsPath(Bitmap bitmap)//Region设定前,Graphicpaths获取函数
{
int iWidth = bitmap.Width;
int iHeight = bitmap.Height;
GraphicsPath graphicpath = new GraphicsPath();
System.Drawing.Color color;
for (int row = 0; row < iHeight; row++)
for (int wid = 0; wid < iWidth; wid++)
{
color = bitmap.GetPixel(wid, row);
//if (255 == color.A)
if (255 == color.A)
graphicpath.AddRectangle(new Rectangle(wid, row, 1, 1));
}
return graphicpath;
}
}
}
准备:新建一窗体,添加一个PictureBox和一个btn
功能:点击btn实现图像翻转
备注:我用的是png格式的图
代码:
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 pathflip
{
public partial class Form1 : Form
{
private GraphicsPath path;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Image image = this.pictureBox1.Image;
image.RotateFlip(RotateFlipType.Rotate180FlipY);
this.pictureBox1.Image = image;
Matrix matrix = new Matrix(-1, 0, 0, 1, image.Width, 0);
this.path.Transform(matrix);
this.pictureBox1.Region = new Region(this.path);
}
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmp = (Bitmap)this.pictureBox1.Image;
this.path = this.CalculateGrahicsPath(bmp);
this.pictureBox1.Region = new Region(this.path);
}
private GraphicsPath CalculateGrahicsPath(Bitmap bitmap)//Region设定前,Graphicpaths获取函数
{
int iWidth = bitmap.Width;
int iHeight = bitmap.Height;
GraphicsPath graphicpath = new GraphicsPath();
System.Drawing.Color color;
for (int row = 0; row < iHeight; row++)
for (int wid = 0; wid < iWidth; wid++)
{
color = bitmap.GetPixel(wid, row);
//if (255 == color.A)
if (255 == color.A)
graphicpath.AddRectangle(new Rectangle(wid, row, 1, 1));
}
return graphicpath;
}
}
}
相关文章推荐
- C# GDI+ 利用 Rectangle GraphicsPath 判断 矩形或多边形 图形关系
- C#中GraphicsPath的Warp方法用法实例
- C#中GraphicsPath的AddString方法用法实例
- c#中GraphicsPath的Flatten方法
- C#中GraphicsPath的Flatten方法用法实例
- c#中GraphicsPath的Widen方法
- C# 获取两个矩形相减部分的GraphicsPath
- c#中GraphicsPath的Warp方法
- c#中GraphicsPath的AddString方法
- C#中GraphicsPath的Widen方法用法实例
- (4.1.36.1)Graphics图形学解析补充篇:路径Path
- android.graphics.Path
- C#基础(19)——path、File类的基本操作
- Path Follow System using Waypoints C#
- (装载)C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
- C# :实现水印与图片合成,并利用Graphics 压缩图像质量 , (委托实现listBox的动态添加提示)
- C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、DirectoryInfo、Path、Encoding)
- GraphicsPath类—可以判断某一点是否在某一个graph的内部
- C#编程技巧之常用文件名、路径处理方法--Path类
- C#调用windows api 函数GetShortPathName