123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Threading.Tasks;
-
- namespace WebApplication3.Clases
- {
- public static class Utilities
- {
- public static bool String2Png(string data)
- {
- Logger.WriteLog("im in");
- bool result = true;
- List<string> rows = data.Split("\r\n",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
- Logger.WriteLog("rows has a lenght of" + rows.Count);
- List<string> cols = rows[0].Split(" ",StringSplitOptions.RemoveEmptyEntries).ToList<string>();
- Logger.WriteLog("cols has a length of " + cols.Count);
- int width = cols.Count;
- int height = rows.Count;
- int[,] integers = new int[height, width];
- int stride = width * 4;
-
- 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
- Random random = new Random();
- 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(@"C:\Users\Admin\Desktop\AAAA\green.png", ImageFormat.Png);
- }
- return result;
- }
- }
- }
|