Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. //Fields
  2. Form myForm = new Form();
  3.  
  4. //Initialize            
  5. System.Windows.Forms.Application.EnableVisualStyles();
  6. Task.Run(() =>System.Windows.Forms.Application.Run(myForm));
  7.  
  8. //Update
  9. for (int x = 0; x < GameManager.Instance.MapSize.x; x++)
  10. {
  11.     for (int y = 0; y < GameManager.Instance.MapSize.y; y++)
  12.     {
  13.         TerrainAnalysis[x, y] = UnityEngine.Random.Range(0f, 1f);
  14.     }
  15. }
  16. CreateBitmapOfTerrainAnalysis(TerrainAnalysis, "TerrainAnalysis");
  17.  
  18. //drawing bitmap method... Specifically the last 2 lines.
  19. /// <summary>
  20. /// Creates a bitmap file of your terrain.
  21. /// </summary>
  22. /// <param name="terrain">The float array used to represent the terrain map. If you used a different data structure, modify this method to accept it.</param>
  23. /// <param name="fileName">The name of the file. Do not include a file extension</param>
  24. private void CreateBitmapOfTerrainAnalysis(float[,] terrain, string fileName)
  25. {
  26.     System.Drawing.Bitmap b = new System.Drawing.Bitmap(GameManager.Instance.MapSize.x, GameManager.Instance.MapSize.y);
  27.     for (int x = 0; x < GameManager.Instance.MapSize.x; x++)
  28.     {
  29.         for (int y = 0; y < GameManager.Instance.MapSize.y; y++)
  30.         {
  31.             b.SetPixel(x, y, System.Drawing.Color.FromArgb((int)(terrain[x, y] * 255), (int)(terrain[x, y] * 255), (int)(terrain[x, y] * 255)));
  32.         }
  33.     }
  34.     b.Save(fileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  35.     System.Drawing.Graphics g = myForm.CreateGraphics();
  36.     g.DrawImage(b, new Point(0, 0));
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement