using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Threading.Tasks; namespace WebApplication3.Clases { public static class Utilities { public static string String2Png(string data) { List rows = data.Split("\r\n",StringSplitOptions.RemoveEmptyEntries).ToList(); List cols = rows[0].Split(" ",StringSplitOptions.RemoveEmptyEntries).ToList(); int width = cols.Count; int height = rows.Count; int[,] integers = new int[height, width]; int stride = width * 4; string fileName = @"C:\Users\Admin\Desktop\AAAA\green.png"; string[,] array2Db = new string[height, width]; for(int i= 0; i < height; i++) { string[] values = rows[i].Split(" ",StringSplitOptions.RemoveEmptyEntries); for(int j= 0; j< width; j++) { string hexColor = Constants._recharge_geometry_colors[values[j]]; array2Db[i, j] = hexColor; } } // Fill array with random values for (int x = 0; x < height; ++x) { for (int y = 0; y < width; ++y) { var color = System.Drawing.ColorTranslator.FromHtml(array2Db[x, y]); byte[] bgra = new byte[] { color.B, color.G, color.R, color.A }; integers[x, y] = BitConverter.ToInt32(bgra, 0); } } Bitmap b; unsafe { fixed (int* intPtr = &integers[0, 0]) { b = new Bitmap(width, height, stride, PixelFormat.Format32bppRgb, new IntPtr(intPtr)); } } using (b) { b.Save(fileName, ImageFormat.Png); } return fileName; } public static void BinaryToFile(byte[] ba, string fileName) { using (FileStream fs = new FileStream(fileName, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(ba); } } } public static bool ModifySVG(string fileOriginal, string x, string y, string length, string height, string destinationFile) { string text = File.ReadAllText(fileOriginal); bool result = true; List textLines = text.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).ToList(); string aux = textLines.Find(x => x.Contains("metadata")); if (aux != null) { try { float latitude = float.Parse(x) + float.Parse(length); float longitude = float.Parse(y) + float.Parse(height); int index = textLines.IndexOf(aux); textLines[index] += "\r\n \r\n < Geo >\r\n < GeoItem X = \"" + 0 + "\" Y = \"" + 0 + "\" Latitude = \"" + x + "\" Longitude = \"" + y + "\" /> < GeoItem X = \"" + x + "\" Y = \"" + y + "\" Latitude = \"" + latitude + "\" Longitude = \"" + longitude + "\" />\r\n \r\n "; File.WriteAllLines(destinationFile, textLines); } catch(Exception ex) { Logger.WriteLog(ex.Message); Logger.WriteLog(ex.InnerException.Message); result = false; ; } } return result; } } }