Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void DrawOnCanvas(bool[,] matrix, Canvas canvas)
- {
- int height = matrix.GetLength(0);
- int width = matrix.GetLength(1);
- //размеры матрицы
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- Ellipse eleps = new Ellipse();
- //создаю элипс
- eleps.Height = 4;
- eleps.Width = 4;
- if (matrix[j , i] == true )
- {
- eleps.Fill = new SolidColorBrush(Colors.Red);
- Canvas.SetLeft(eleps, i * 5);
- Canvas.SetTop(eleps, j * 5);
- canvas.Children.Add(eleps);
- //добавляю его на канвас если в атрице 1
- }
- }
- }
- }
- public static void DrawOnImage(bool[,] outmatrix, Image img)
- {
- WriteableBitmap wb = new WriteableBitmap((int)img.Width,
- (int)img.Height, 1, 1, PixelFormats.Bgra32, null);//создаем типо битмап указывая ширину и высоту формат пиксилей и чето еще вроде как dpi
- Int32Rect rect = new Int32Rect(0, 0, (int)img.Width, (int)img.Height);
- byte[] pixels = new byte[(int)img.Width * (int)img.Height * wb.Format.BitsPerPixel / 8];
- int alpha = 255;
- int red = 0;
- int green = 0;
- int blue = 0;
- int height = outmatrix.GetLength(0);
- int width = outmatrix.GetLength(1);
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- if ((outmatrix[j, i] == true))
- {
- red = 255;
- }
- else
- {
- red = 0;
- }
- int pixelOffset = (i + j * wb.PixelWidth) * wb.Format.BitsPerPixel / 8;
- pixels[pixelOffset] = (byte)red;
- pixels[pixelOffset + 1] = (byte)green;
- pixels[pixelOffset + 2] = (byte)blue;
- pixels[pixelOffset + 3] = (byte)alpha;
- }
- int stride = (wb.PixelWidth * wb.Format.BitsPerPixel / 8); //шаги
- wb.WritePixels(rect, pixels, stride, 0);
- }
- img.Source = wb;
- }
Add Comment
Please, Sign In to add comment