C# winform窗口图片旋转
来源:互联网 发布:吴炳亮fifa淘宝 编辑:程序博客网 时间:2024/04/28 20:36
//可以实现任意角度的旋转,旋转出现的角落空白可以选择填充的颜色。
using System;
using System.Drawing;using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
namespace bitmaprerote
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor)
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap map = new Bitmap("F:\\hj.jpg");
this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
map = KiRotate(map, 30, Color.Pink);
pictureBox1.Image = map;
}
}
}
0 0
- C# winform窗口图片旋转
- c# winform任意角度图片旋转
- winform图片旋转
- winform PictureBox 图片旋转
- C# Winform多窗口
- 图片纠正旋转c#
- C# winform 窗口属性详解
- C# winform 上传文件、图片
- C# winform DevExpress上传图片
- c# 窗口图片绘制
- C# WinForm窗口最小化到系统托盘
- C# WinForm窗口最小化到系统托盘
- C# winform登录窗口关闭方法
- C# WinForm窗口最小化到系统托盘
- C# WinForm窗口最小化到系统托盘(Holym)
- C#实现WinForm窗口最小化到系统托盘
- C# 日记5--Winform属性窗口
- C# WinForm登录窗口原理代码
- scanf函数
- 面试题总结16 对一个整数开根号
- Linux下C++手动编译,链接过程
- LeetCode-Evaluate Reverse Polish Notation
- 地图网站显示实时交通路况信息的原理
- C# winform窗口图片旋转
- 双向链表
- [学习笔记]栈的顺序存储结构和两栈共享空间
- Flex 使用 as3xls包导出Excel避免长数字转换成科学计数法
- css定位流测试实验效果与代码分析
- Ural1137(欧拉回路)
- JSONKIT isa错误的解决办法
- 黑马交通灯系统
- 我去热问题