日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

XML图集拆分

發(fā)布時(shí)間:2023/12/15 asp.net 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XML图集拆分 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

最近找了套老游戲的資源圖集,合圖生成的文件是xml的,沒有找到拆圖的工具,所以自己寫了個(gè)

可以通過(guò)修改拆分任何格式配置的圖集,代碼如下,vs粘上可以直接使用


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Xml;

namespace xmlpng
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? while (true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("start!");
? ? ? ? ? ? ? ? //讀取xml
? ? ? ? ? ? ? ? string xmlPath = Console.ReadLine();
? ? ? ? ? ? ? ? Console.WriteLine(xmlPath);

? ? ? ? ? ? ? ? string imagePath = xmlPath.Substring(0, xmlPath.LastIndexOf('.') + 1) + "png";
? ? ? ? ? ? ? ? Console.WriteLine(imagePath);

? ? ? ? ? ? ? ? string saveRootPath = xmlPath.Substring(0, xmlPath.LastIndexOf('.'));
? ? ? ? ? ? ? ? System.IO.Directory.CreateDirectory(saveRootPath);
? ? ? ? ? ? ? ? XmlTextReader reader = new XmlTextReader(xmlPath);
? ? ? ? ? ? ? ? while (reader.Read())
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (reader.Name == "spr")
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? string name = reader.GetAttribute("name");
? ? ? ? ? ? ? ? ? ? ? ? string path = saveRootPath + "\\" + name + ".png";
? ? ? ? ? ? ? ? ? ? ? ? int x = int.Parse(reader.GetAttribute("x")) * 2;
? ? ? ? ? ? ? ? ? ? ? ? int y = int.Parse(reader.GetAttribute("y")) * 2;
? ? ? ? ? ? ? ? ? ? ? ? int w = int.Parse(reader.GetAttribute("w")) * 2;
? ? ? ? ? ? ? ? ? ? ? ? int h = int.Parse(reader.GetAttribute("h")) * 2;

? ? ? ? ? ? ? ? ? ? ? ? Console.WriteLine(name + "|" + x + "|" + y + "|" + w + "|" + h + "|" + path);
? ? ? ? ? ? ? ? ? ? ? ? CaptureImage(imagePath, path, w, h, x, y);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }

? ? ? ? }
? ? ? ? public static void CaptureImage(string sFromFilePath, string saveFilePath, int width, int height, int spaceX, int spaceY)
? ? ? ? {
? ? ? ? ? ? //載入底圖???
? ? ? ? ? ? Image fromImage = Image.FromFile(sFromFilePath);
? ? ? ? ? ? int x = 0; ? //截取X坐標(biāo)???
? ? ? ? ? ? int y = 0; ? //截取Y坐標(biāo)???
? ? ? ? ? ? int sX = fromImage.Width - width;
? ? ? ? ? ? int sY = fromImage.Height - height;
? ? ? ? ? ? if (sX > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? x = sX > spaceX ? spaceX : sX;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? width = fromImage.Width;
? ? ? ? ? ? }
? ? ? ? ? ? if (sY > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? y = sY > spaceY ? spaceY : sY;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? height = fromImage.Height;
? ? ? ? ? ? }

? ? ? ? ? ? //創(chuàng)建新圖位圖???
? ? ? ? ? ? Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
? ? ? ? ? ? //創(chuàng)建作圖區(qū)域???
? ? ? ? ? ? Graphics graphic = Graphics.FromImage(bitmap);
? ? ? ? ? ? //截取原圖相應(yīng)區(qū)域?qū)懭胱鲌D區(qū)???
? ? ? ? ? ? graphic.DrawImage(fromImage, 0, 0, new Rectangle(x, y, width, height), GraphicsUnit.Pixel);
? ? ? ? ? ? bitmap.Save(saveFilePath, bitmap.RawFormat);

? ? ? ? ? ? bitmap.Dispose();
? ? ? ? ? ? graphic.Dispose();
? ? ? ? }

? ? }
}
?

總結(jié)

以上是生活随笔為你收集整理的XML图集拆分的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。