Guest User

Untitled

a guest
Mar 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. public static void DrawOnCanvas(bool[,] matrix, Canvas canvas)
  2. {
  3. int height = matrix.GetLength(0);
  4. int width = matrix.GetLength(1);
  5. //размеры матрицы
  6. for (int i = 0; i < width; i++)
  7. {
  8. for (int j = 0; j < height; j++)
  9. {
  10. Ellipse eleps = new Ellipse();
  11. //создаю элипс
  12. eleps.Height = 4;
  13. eleps.Width = 4;
  14. if (matrix[j , i] == true )
  15. {
  16. eleps.Fill = new SolidColorBrush(Colors.Red);
  17. Canvas.SetLeft(eleps, i * 5);
  18. Canvas.SetTop(eleps, j * 5);
  19. canvas.Children.Add(eleps);
  20. //добавляю его на канвас если в атрице 1
  21. }
  22. }
  23. }
  24. }
  25.  
  26. public static void DrawOnImage(bool[,] outmatrix, Image img)
  27. {
  28. WriteableBitmap wb = new WriteableBitmap((int)img.Width,
  29. (int)img.Height, 1, 1, PixelFormats.Bgra32, null);//создаем типо битмап указывая ширину и высоту формат пиксилей и чето еще вроде как dpi
  30.  
  31.  
  32. Int32Rect rect = new Int32Rect(0, 0, (int)img.Width, (int)img.Height);
  33.  
  34. byte[] pixels = new byte[(int)img.Width * (int)img.Height * wb.Format.BitsPerPixel / 8];
  35. int alpha = 255;
  36. int red = 0;
  37. int green = 0;
  38. int blue = 0;
  39. int height = outmatrix.GetLength(0);
  40. int width = outmatrix.GetLength(1);
  41. for (int i = 0; i < width; i++)
  42. {
  43. for (int j = 0; j < height; j++)
  44. {
  45.  
  46. if ((outmatrix[j, i] == true))
  47. {
  48. red = 255;
  49. }
  50. else
  51. {
  52. red = 0;
  53. }
  54. int pixelOffset = (i + j * wb.PixelWidth) * wb.Format.BitsPerPixel / 8;
  55. pixels[pixelOffset] = (byte)red;
  56. pixels[pixelOffset + 1] = (byte)green;
  57. pixels[pixelOffset + 2] = (byte)blue;
  58. pixels[pixelOffset + 3] = (byte)alpha;
  59. }
  60.  
  61. int stride = (wb.PixelWidth * wb.Format.BitsPerPixel / 8); //шаги
  62.  
  63. wb.WritePixels(rect, pixels, stride, 0);
  64. }
  65. img.Source = wb;
  66. }
Add Comment
Please, Sign In to add comment