123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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<string> rows = data.Split("\r\n",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
- List<string> cols = rows[0].Split(" ",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
- 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<string> 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 <MetaInfo xmlns=\"http://www.prognoz.ru\">\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 </ Geo >\r\n </ MetaInfo > ";
- File.WriteAllLines(destinationFile, textLines);
- }
- catch(Exception ex)
- {
- Logger.WriteLog(ex.Message);
- Logger.WriteLog(ex.InnerException.Message);
- result = false; ;
- }
- }
-
- return result;
- }
- }
- }
|