.net 图片操作

embedded/2024/9/20 3:52:16/ 标签: .net

图片操作 bitmap 旋转 bitmap左右镜像

/// <summary>/// bitmap角度旋转/// </summary>/// <param name="image"></param>/// <param name="angle"></param>/// <returns></returns>public static Bitmap RotateImage(Bitmap image, int angle){try{// 创建一个新的Bitmap对象,宽度和高度互换Bitmap rotatedImage = new Bitmap(image.Height, image.Width);// 创建一个Graphics对象,并设置其绘制原点为新图像的中心点using (Graphics g = Graphics.FromImage(rotatedImage)){g.TranslateTransform(rotatedImage.Width / 2, rotatedImage.Height / 2);// 设置旋转角度为90度g.RotateTransform(angle);// 将原图像绘制到新图像上g.DrawImage(image, -image.Width / 2, -image.Height / 2, image.Width, image.Height);return rotatedImage;}}catch (AccessViolationException ave){return null;}}/// <summary>///  bitmap角度旋转/// </summary>/// <param name="originalImage"></param>/// <param name="angle"></param>/// <returns></returns>public static Bitmap RotateImage2(Bitmap originalImage, float angle){// 计算旋转后的包围矩形大小int width = originalImage.Width;int height = originalImage.Height;double radians = angle * Math.PI / 180.0;double sin = Math.Abs(Math.Sin(radians));double cos = Math.Abs(Math.Cos(radians));int newWidth = (int)Math.Floor(width * cos + height * sin);int newHeight = (int)Math.Floor(width * sin + height * cos);// 创建一个新的Bitmap,大小足够容纳旋转后的图像Bitmap rotatedImage = new Bitmap(newWidth, newHeight);using (Graphics g = Graphics.FromImage(rotatedImage)){// 设置插值模式和平滑模式g.InterpolationMode = InterpolationMode.HighQualityBicubic;g.SmoothingMode = SmoothingMode.HighQuality;g.PixelOffsetMode = PixelOffsetMode.HighQuality;g.CompositingQuality = CompositingQuality.HighQuality;// 计算旋转后的位置,以便将原始图像绘制到新的Bitmap中心Point center = new Point(newWidth / 2, newHeight / 2);g.TranslateTransform(center.X, center.Y);g.RotateTransform(angle);g.TranslateTransform(-center.X, -center.Y);// 在新的Bitmap上绘制旋转后的图像g.DrawImage(originalImage, new Point((newWidth - width) / 2, (newHeight - height) / 2));}return rotatedImage;}/// <summary>/// 图像镜像转换/// </summary>/// <param name="originalBitmap"></param>/// <returns></returns>public static Bitmap BitmapImage2(Bitmap originalImage){{// 创建一个与原始图片大小相同的空白图片Bitmap flippedImage = new Bitmap(originalImage.Width, originalImage.Height);// 获取空白图片的绘图对象using (Graphics g = Graphics.FromImage(flippedImage)){// 水平翻转图片g.DrawImage(originalImage, new Rectangle(0, 0, flippedImage.Width, flippedImage.Height),new Rectangle(originalImage.Width, 0, -originalImage.Width, originalImage.Height),GraphicsUnit.Pixel);}// 保存翻转后的图片return flippedImage;}}public static Bitmap BitmapImage(Bitmap originalBitmap){// 创建一个新的Bitmap,大小与原始相同Bitmap mirroredBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height);// 循环遍历原始Bitmap的像素for (int y = 0; y < originalBitmap.Height; y++){for (int x = 0; x < originalBitmap.Width; x++){// 获取原始Bitmap中的像素颜色Color originalColor = originalBitmap.GetPixel(x, y);// 计算水平翻转后的x坐标int mirroredX = originalBitmap.Width - 1 - x;// 在新Bitmap上设置镜像像素mirroredBitmap.SetPixel(mirroredX, y, originalColor);}}return mirroredBitmap;}

http://www.ppmy.cn/embedded/22461.html

相关文章

0418EmpTomCat项目 初次使用ajax实现局部动态离职

0418EmpTomCat项目包-CSDN博客 数据库字段&#xff1a; 员工部门表 分页查询&#xff1b; 多条件查询&#xff1b; 添加新员工&#xff1b; ajax点击离职操作效果&#xff1a;

PhotosCollage for Mac:优雅且实用的照片拼贴软件

PhotosCollage for Mac是一款优雅且实用的照片拼贴软件&#xff0c;为Mac用户提供了一个便捷、高效的平台&#xff0c;以创建精美、个性化的照片拼贴作品。 PhotosCollage for Mac v1.4.1激活版下载 该软件界面简洁直观&#xff0c;操作便捷。用户只需将想要拼贴的照片拖入“照…

k8s pod 镜像拉取策略

在 Kubernetes (k8s) 中&#xff0c;Pod 容器镜像的拉取策略通过 imagePullPolicy 属性来控制。这一策略决定了 kubelet 如何以及何时从容器镜像仓库中拉取镜像。以下是三种主要的镜像拉取策略及其详细说明&#xff1a; Always: 说明: 这是默认的拉取策略。当设置为 Always 时&…

从NoSQL到NewSQL——10年代大数据浪潮下的技术革新

引言 在数字化浪潮的推动下&#xff0c;数据库技术已成为支撑数字经济的坚实基石。腾讯云 TVP《技术指针》联合《明说三人行》特别策划的直播系列——【中国数据库前世今生】&#xff0c;我们将通过五期直播&#xff0c;带您穿越五个十年&#xff0c;深入探讨每个时代的数据库演…

mysql 开启远程连接

登录到mysql mysql -uroot -p 打开mysql数据库并查询user表 use mysql; select user, host from user;更改需要远程连接数据库为任何ip 可以连接&#xff0c; 并刷新系统权限相关的表 update user set host% where hostlocalhost and userroot; flush privileges;

Apache Flink 流处理-[CentOS|Rocky] 镜像

Flink Docker仓库包含了Dockerfiles用于为Flink构建docker images使用&#xff0c;这些 Dockerfile 由 Apache Flink 社区维护&#xff0c;但 Docker 社区负责在 Docker Hub 上构建和托管映像。目前市面上流行的Flink镜像都是基于Ubuntu镜像构建&#xff0c;由于项目需求变化&a…

3. uniapp开发工具的一些事

前言 新的一天&#xff0c;又要开始卷起来了&#xff0c;开发程序开发当前离不开开发工具&#xff0c;一个好的开发工具办事起来那必然是事倍功半的...本文主要分享了关于uniapp里开发工具的一些事~ 概述 阅读时间&#xff1a;约5&#xff5e;7分钟&#xff1b; 本文重点&am…

020Node.js的FS模块使用fs.mkdir创建目录

Node.js的FS模块使用fs.mkdir创建目录 //fs.mkdir 创建目录 /*path 将创建的目录路径mode 目录权限&#xff08;读写权限&#xff09;&#xff0c;默认777callback 回调&#xff0c;传递异常参数err*/ const fsrequire(fs);fs.mkdir(./css,(err)>{if(err){console.log(err)…

MySql:连接和关闭

c connector 下面是一个示例&#xff0c;世界使用c connector时注意release版本和debug版本要和响应的动态库匹配才可以 #include <mysql_driver.h> #include <mysql_connection.h> #include <cppconn/resultset.h> #include <cppconn/statement.h>i…

UDP和TCP(传输层)

这里写目录标题 UDPUDP的基本特点UDP协议报文格式 TCPTCP协议报文格式TCP特点可靠传输实现机制确认应答超时重传数据丢了应答报文丢了 小结 UDP UDP的基本特点 无连接不可靠传输面向数据报全双工 UDP协议报文格式 2个字节有效范围(无符号): 0 ~ 65535(2^16 - 1). 2个字节有效范…

Pytorch迁移学习训练病变分类模型

划分数据集 1.创建训练集文件夹和测试集文件夹 # 创建 train 文件夹 os.mkdir(os.path.join(dataset_path, train))# 创建 test 文件夹 os.mkdir(os.path.join(dataset_path, val))# 在 train 和 test 文件夹中创建各类别子文件夹 for Retinopathy in classes:os.mkdir(os.pa…

JS常用数据类型的方法函数调用,数组的方法、对象的方法、字符串的方法、数字的方法、集合的方法、映射的方法、栈的方法、队列的方法、链表的封装、树的封装、

JS常用数据类型的方法函数调用&#xff0c;数组的方法、对象的方法、字符串的方法、数字的方法、集合的方法、映射的方法、栈的方法、队列的方法、链表的封装、树的封装 1. 数组&#xff08;Array&#xff09;&#xff1a;数组是一组按顺序存储的元素的集合&#xff1a;2. 对象…

GPT的全面历史和演变:从GPT-1到GPT-4

人工智能新篇章&#xff1a;GPT-4与人类互动的未来&#xff01; 本文探讨了生成式预训练 Transformer (GPT) 的显着演变&#xff0c;提供了从开创性的 GPT-1 到复杂的 GPT-4 的旅程。 每次迭代都标志着重大的技术飞跃&#xff0c;深刻影响人工智能领域以及我们与技术的互动。 我…

feign整合sentinel做降级知识点

1&#xff0c;配置依赖 <!-- Feign远程调用依赖 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency> <!--sentinel--><dependency>…

微软开源了 MS-DOS 4.00

DOS的历史源远流长&#xff0c;很多现在的年轻人不知道DOS了。其实早期的windows可以看做是基于DOS的窗口界面的模拟器&#xff0c;系统的本质其实是DOS。后来DOS的漏洞还是太多了&#xff0c;微软重新写了windows的底层内核。DOS只是一个辅助终端的形式予以保留了。 微软是在…

golang上传文件到ftp服务器

之前有个业务需要把文件上传到ftp服务器&#xff0c;写了一个上传ftp的功能 package ftpimport "context"type Client interface {// UploadFile 上传文件UploadFile(ctx context.Context, opt *UploadFileOpt) error }type UploadFileOpt struct {Data […

操作系统——优先权算法c++实现

变量描述 测试数据 5 A 0 4 4 B 1 3 2 C 2 5 3 D 3 2 5 E 4 4 1 先来先服务算法 简述 该算法实现非常简单就是对到达时间排个序&#xff0c;然后依次进行即可&#xff0c;对结构体的sort进行了重载 代码 void FCFS() {//先来先服务算法std::cout<<"\n\t\t\t\t\…

灌溉排涝乙级资质升级甲级,这些材料你准备好了吗?

在灌溉排涝行业&#xff0c;资质的升级不仅是企业实力的一种体现&#xff0c;更是开拓新市场、参与更多大型项目的必要条件。从乙级资质升级到甲级&#xff0c;企业需要跨越一个较高的门槛&#xff0c;准备一系列详尽而严谨的材料。以下就是你需要准备的关键材料清单&#xff0…

Cocos Creator 3D物理引擎的物理参数控制详解

前言 Cocos Creator是一款基于JavaScript和TypeScript的开源游戏引擎&#xff0c;它提供了强大的3D物理引擎&#xff0c;可以帮助开发者实现各种物理效果。在Cocos Creator中&#xff0c;我们可以通过控制物理参数来实现不同的物理效果&#xff0c;比如重力、碰撞检测、摩擦力…

后端学习记录~~JavaSE篇(Module08-异常 上 )

总览&#xff1a; Java概述&#xff1a; 思维导图文件在本人个人主页上-----资源模块 资源详情&#xff08;免费下载&#xff09;&#xff1a;Java学习思维导图异常篇资源-CSDN文库https://download.csdn.net/download/m0_61589682/89238330 整体展示&#xff1a;