Winform以任意角度旋转PictureBox中的图片的方法
方法1:
private void RotateFormCenter(PictureBox pb, float angle)
{
Image img = pb.Image;
int newWidth = Math.Max(img.Height, img.Width);
Bitmap bmp = new Bitmap(newWidth, newWidth);
Graphics g = Graphics.FromImage(bmp);
Matrix x = new Matrix();
PointF point = new PointF(img.Width / 2f, img.Height / 2f);
x.RotateAt(angle, point);
g.Transform = x;
g.DrawImage(img, 0, 0);
g.Dispose();
img = bmp;
pb.Image = img;
}
该方法通过将图片转化为用于几何变换的3x3矩阵 对图片进行旋转。
缺点:有时图片会越转越模糊。
方法2:
private void RotateFormCenter(PictureBox pb, float angle)
{
Graphics graphics = pb.CreateGraphics();
graphics.Clear(pb.BackColor);
//装入图片
Bitmap image = new Bitmap(pb.Image);
//获取当前窗口的中心点
Rectangle rect = new Rectangle(, , pb.Width, pb.Height);
PointF center = new PointF(rect.Width / , rect.Height / );
float offsetX = ;
float offsetY = ;
offsetX = center.X - image.Width / ;
offsetY = center.Y - image.Height / ;
//构造图片显示区域:让图片的中心点与窗口的中心点一致
RectangleF picRect = new RectangleF(offsetX, offsetY, image.Width, image.Height);
PointF Pcenter = new PointF(picRect.X + picRect.Width / ,
picRect.Y + picRect.Height / );
// 绘图平面以图片的中心点旋转
graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
graphics.RotateTransform(angle);
//恢复绘图平面在水平和垂直方向的平移
graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y);
//绘制图片
graphics.DrawImage(image, picRect);
}
通过操作Graphics进行图像旋转,使用时需要注意图片是按原始大小进行居中旋转 PictureBox的SizeMode属性对这种方法无效。
Winform以任意角度旋转PictureBox中的图片的方法的更多相关文章
- JAVA对图片的任意角度旋转,以及镜像操作
package relevantTest;/* * 该代码实现了对图像的水平镜像变换,垂直镜像变换,任意角度旋转,jtf的实时监控,以及对图像的缩放变换,以及按钮的若隐若现效果. * 在对图像进行任意 ...
- C# 保存PictureBox中的图片到数据库,并从数据库读取图片显示到PictrueBox,解决报错 “无效参数”
下面是两段关键代码: /// <summary> /// 将一张图片转换为字节 /// </summary> /// <param name="img" ...
- 在Altium_Designer_PCB_中插入图片的方法
详细请看PDF: http://files.cnblogs.com/files/BinB-W/在Altium_Designer_PCB_中插入图片的方法.pdf 配套文件: http://files. ...
- 在word中输入任意角度旋转图片
Sub 图片旋转任意角度() Dim sha As Shape, isa As InlineShape Static s As Integer Application.ScreenUpdating = ...
- Java实现图片内容无损任意角度旋转
转自:http://blog.csdn.net/heliang7/article/details/7309394 主要问题是如何在图片做旋转后计算出新图片的长宽. 在java 2d和基本math库的帮 ...
- CSS中背景图片定位方法
转自:http://www.ruanyifeng.com/blog/2008/05/css_background_image_positioning.html 作者: 阮一峰 日期: 2008年5月 ...
- Java中显示图片的方法
最近在做一个swing小项目,其中需要把存储在硬盘中的图片文件显示出来,总结了如下方法: 1. Graphics g = getGraphics();String name = "E:/Ca ...
- Dede 删除文档同时文章中的图片的方法
首先,在"/include"目录下建立"extend.func.php"文件. 然后,将以下内容保存在"extend.func.php"文件 ...
- (转)HTML&CSS——background: url() no-repeat 0 -64px;CSS中背景图片定位方法
http://blog.csdn.net/oscar92420aaa/article/details/51304067 CSS中背景图片的定位,困扰我很久了.今天总算搞懂了,一定要记下来. 在CSS中 ...
随机推荐
- Android Studio使用百度地图示例BaiduMapsApiASDemo
Android Studio使用百度地图示例BaiduMapsApiASDemo 用自己AVD下的debug.keystore替换掉项目中的debug.keystore 生成自己的签名 同样的方法生成 ...
- 完整地mybatis + springmvc用checkbox实现批量删除
因为自己在网上找了半天,都找不到完整地代码(脑袋笨,不会变通到自己项目里),所以在这里记下了近乎完整的代码 前端代码 <span style="cursor:pointer;" ...
- Fatal error: Allowed memory size of 524288000 bytes exhausted (tried to allocate 64 bytes) in D
Fatal error: Allowed memory size of 524288000 bytes exhausted (tried to allocate 64 bytes) in D 从数据库 ...
- AFN中的PATCH 和 DELETE 请求方式
- (nullable NSURLSessionDataTask *)PATCH:(NSString *)URLString parameters:(nullable id)parameters su ...
- EXCEL拼接SQL
=CONCATENATE("insert into 表名 (字段名1,字段名2)values (3, '"&C3&"');") 用CONCAT ...
- Windows XP SP3下编译安装check-0.10.0
软件环境:visual studio 2010 cmake-3.6.3-win32-x86 从github.com下载check-0.10.0到本地,解压出目录check-0.10.0 下载cmake ...
- sendto频率过快导致发送丢包
编写一个转发模块,虽然没有要求一转多时要达到多少路(不采用组播的情况下,单纯的一路转成多路),但是本着物尽其用的原则,尽可能测试一下极限. 网络环境:1000M,直连,多网卡 系统:Linux ver ...
- 用grunt进行前端工程化之路
我们的项目wecash4.0的前端构建考虑过用fis和grunt. 目录: 前期调研:fis vs grunt vs gulp? 一.安装grunt和项目. fis是百度fex研发的构建工具,非常方便 ...
- #include <cstdio>
#include <cstdio> using namespace std; int main() { int gx; gx=6; printf("%d\n",gx); ...
- JSP目录
JSP目录 课时1 jsp概述和背后原理31:11 课时2 三种jsp的scriptlet语法27:29 课时3 jsp的注释14:00 课时4 JSP4个域对象的作用域3 ...