Skip to content

Instantly share code, notes, and snippets.

@amirburbea
Created June 28, 2020 19:39
Show Gist options
  • Save amirburbea/b1cca24950de191c2fce558a1dbbf7cf to your computer and use it in GitHub Desktop.
Save amirburbea/b1cca24950de191c2fce558a1dbbf7cf to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Microsoft.VisualBasic.CompilerServices;
namespace KoARImages
{
class Program
{
static void Main()
{
//using Stream stream = File.OpenRead(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "item_information_template.xml"));
//XDocument document = XDocument.Load(stream);
//foreach (var g in from node in document.Root.Descendants("tex")
// where node.NodeType == XmlNodeType.Element
// let texture = node.Attribute("texture").Value
// group (XElement)node by texture into g
// select g)
//{
// string filePath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "pngs", $"{g.Key}.png");
// if (!File.Exists(filePath))
// {
// continue;
// }
// string targetFolder = Path.Join(AppDomain.CurrentDomain.BaseDirectory, g.Key);
// if (!Directory.Exists(targetFolder))
// {
// Directory.CreateDirectory(targetFolder);
// }
// using Bitmap source = (Bitmap)Image.FromFile(filePath);
// foreach (var element in g)
// {
// string id = (element.Attribute("id_string") ?? element.Parent.Attribute("id_string")).Value;
// int left = int.Parse(element.Attribute("left").Value);
// int top = int.Parse(element.Attribute("top").Value);
// int right = int.Parse(element.Attribute("right").Value);
// int bottom = int.Parse(element.Attribute("bottom").Value);
// if (left == right - 1)
// {
// Console.WriteLine(id);
// }
// else
// {
// using Bitmap clone = source.Clone(new Rectangle(left, top, right - left, bottom - top), source.PixelFormat);
// clone.Save(Path.Join(targetFolder, $"{id}.png"));
// }
// }
//}
for (int i = 0; i < 2; i++)
{
string key = "ui_icons_inv_weapons_common" + (i == 0 ? "" : "_02");
using Bitmap source = (Bitmap)Image.FromFile(Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "pngs", key + ".png"));
string targetFolder = Path.Join(AppDomain.CurrentDomain.BaseDirectory, key);
if (!Directory.Exists(targetFolder))
{
Directory.CreateDirectory(targetFolder);
}
for (int left = 0; left < 512; left += 64)
{
for (int top = 0; top < 512; top += 64)
{
using Bitmap clone = source.Clone(new Rectangle(left, top, 64, 64), source.PixelFormat);
clone.Save(Path.Join(targetFolder, $"{left/64 }_{top/64}.png"));
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment