当前位置: 首页 > news >正文

【C#】制作图集

如题目,用好几个图片拼在一个大图里,博主是用于Unity游戏开发使用的,话不多说,上代码!

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;namespace EffectsPackTool.Common
{/// <summary>/// 图集处理共通方法/// </summary>public static class SpriteSheet{/// <summary>/// 创建图集/// </summary>/// <param name="imagePaths">图片地址集</param>/// <param name="outputPath">输出路径</param>/// <param name="maxWidth">画布最大宽度</param>/// <param name="maxHeight">画布最大高度</param>/// <param name="imageMaxHeight">图片最大高度</param>public static bool CreateSpriteSheet(IEnumerable<string> imagePaths, string outputPath, int maxWidth, int maxHeight, int imageMaxHeight){try{using (Bitmap spriteSheet = new Bitmap(maxWidth, maxHeight)){using (Graphics g = Graphics.FromImage(spriteSheet)){g.Clear(Color.Transparent); // 如果需要透明背景可以设置int currentHeight = 0;int currentWidth = 0;foreach (string imagePath in imagePaths){using (Image image = Image.FromFile(imagePath)){// 检查是否超出最大宽度,如果是,则移至下一行if (image.Width + currentWidth > maxWidth){currentHeight += imageMaxHeight;currentWidth = 0;}// 绘制图像到sprite sheetg.DrawImage(image, new Point(currentWidth, currentHeight));// 更新当前宽度currentWidth += image.Width;}}}// 保存sprite sheet到指定路径spriteSheet.Save(outputPath, ImageFormat.Png);}return true;}catch (Exception ex){return false;}}}
}

没什么好说的 拿去直接用就行

完结!

http://www.lryc.cn/news/388348.html

相关文章:

  • 行列视报表系统制作的报表与厂级监控信息系统(SIS)系统中的报表有什么区别?
  • 算法08 广/宽度优先搜索及相关问题详解
  • PyTorch 版本与 CUDA 版本的兼容性示例
  • Selenium进行Web自动化滚动
  • 机器学习模型训练过程和预测过程 用孩子来生动的比喻 --九五小庞
  • 【爱上C++】详解string类2:模拟实现、深浅拷贝
  • 狄克斯特拉算法
  • 2024推荐整理几个磁力导航网站可提供海量资源的
  • 链式访问:C语言中的函数调用技巧
  • 数据库设计(实战项目)-1个手机号多用户身份
  • vue+fineReport 使用前端搜索+报表显示数据
  • 高阶面试-存储系统的设计
  • 柔性测斜仪:土木工程与地质监测的得力助手
  • 数字资产和数据资产你真的了解吗?
  • 【每日一练】python运算符
  • CesiumJS【Basic】- #032 绘制虚线(Primitive方式)
  • 海尔智家:科技优秀是一种习惯
  • 【Android】实现图片和视频混合轮播(无限循环、视频自动播放)
  • VLAN基础
  • pytest-yaml-sanmu(五):跳过执行和预期失败
  • linux指令整合(centos系统持续更新中。。。)
  • 个人开发实现AI套壳网站快速搭建(Vue+elementUI+SpringBoot)
  • Cesium与Three相机同步(3)
  • PMP考试报名项目经历怎么填写?指引请收好
  • Git的基本使用方法
  • 深入剖析 @Autowired 和 @Resource 在 Spring 中的区别
  • Golang-slice理解
  • 【Linux系统】文件描述符fd
  • 【嵌入式——FreeRTOS】启动任务调度器
  • EFCore_客户端评估与服务端评估