private void imgCubeWhite_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { BitmapSource visual_BitmapSource = get_BitmapSource_of_Element(imgCubeWhite); CroppedBitmap cb = new CroppedBitmap(visual_BitmapSource, new Int32Rect((int)Mouse.GetPosition(imgCubeWhite).X, (int)Mouse.GetPosition(imgCubeWhite).Y, 1, 1)); byte[] pixels = new byte[4]; try { cb.CopyPixels(pixels, 4, 0); } catch (Exception) { //error } rectSelected.Fill = new SolidColorBrush(Color.FromRgb(pixels[2], pixels[1], pixels[0])); Brush newColor = new SolidColorBrush(Color.FromRgb(pixels[2], pixels[1], pixels[0])); SolidColorBrush scb = (SolidColorBrush)newColor; Color col = scb.Color; PaintCanvas.DefaultDrawingAttributes.Color = col; PaintCanvas.EditingMode = InkCanvasEditingMode.Ink; }
private void SamplePixelForColor() { // Retrieve the coordinate of the mouse position in relation to the supplied image. var point = Mouse.GetPosition(AssociatedObject); // Use RenderTargetBitmap to get the visual, in case the image has been transformed. var renderTargetBitmap = new RenderTargetBitmap((int)AssociatedObject.ActualWidth, (int)AssociatedObject.ActualHeight, 96, 96, PixelFormats.Default); renderTargetBitmap.Render(AssociatedObject); // Make sure that the point is within the dimensions of the image. if ((point.X <= renderTargetBitmap.PixelWidth) && (point.Y <= renderTargetBitmap.PixelHeight)) { // Create a cropped image at the supplied point coordinates. var croppedBitmap = new CroppedBitmap(renderTargetBitmap, new Int32Rect((int)point.X, (int)point.Y, 1, 1)); // Copy the sampled pixel to a byte array. var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); // Assign the sampled color to a SolidColorBrush and return as conversion. SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); } }
/// <summary> /// Returns a color structure representing the color of the pixel at the current mouse x and y coordinates /// </summary> /// <returns>A color structure</returns> internal static Color GetPointColor(FrameworkElement control) { // Retrieve the relative coordinate of the mouse position in relation to the current window var point = Mouse.GetPosition(control); // Grab a bitmap of the current window var renderTargetBitmap = new RenderTargetBitmap((int)control.ActualWidth, (int)control.ActualHeight, 96, 96, PixelFormats.Default); renderTargetBitmap.Render(control); // Determine if we are in bounds if ((point.X <= renderTargetBitmap.PixelWidth) && (point.Y <= renderTargetBitmap.PixelHeight)) { // Crop a pixel out of the larger bitmap var croppedBitmap = new CroppedBitmap(renderTargetBitmap, new Int32Rect((int)point.X, (int)point.Y, 1, 1)); // Copy the pixel to a byte array var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); // Convert the RGB byte array to a Color structure var selectedColor = Color.FromRgb(pixels[2], pixels[1], pixels[0]); return(selectedColor); } return(Colors.Black); }
private void CanvasPanel_MouseMove(object sender, MouseEventArgs e) { if (_isMouseDown) { var x = Mouse.GetPosition(CanvasPanel).X; var y = Mouse.GetPosition(CanvasPanel).Y; if (x >= _ellipseHalfWidth && x <= CanvasImage.Width - _ellipseHalfWidth - 1 && y >= _ellipseHalfHeight && y <= CanvasImage.Height - _ellipseHalfHeight - 1) { try { var croppedBitmap = new CroppedBitmap(ColorImage.Source as BitmapSource, new Int32Rect(Convert.ToInt32(x), Convert.ToInt32(y), 1, 1)); var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); MoveEllipse(x, y, SelectedColor); UpdateTextBox(); ColorRectangle.Fill = new SolidColorBrush(SelectedColor); } catch (Exception) { _isMouseDown = false; SetColor(Colors.White); } finally { CanvasImage.InvalidateVisual(); } } else { _isMouseDown = false; } } }
private void Image_MouseDown(object sender, MouseButtonEventArgs e) { try { var cb = new CroppedBitmap((BitmapSource)(((Image)e.Source).Source), new Int32Rect((int)Mouse.GetPosition(e.Source as Image).X, (int)Mouse.GetPosition(e.Source as Image).Y, 1, 1)); _pixels = new byte[4]; try { cb.CopyPixels(_pixels, 4, 0); SetColor(Color.FromRgb(_pixels[2], _pixels[1], _pixels[0])); UpdateMarkerPosition(); if (OnColorSelected != null) { OnColorSelected(SelectedColor); } } catch { // not logged } UpdateSlider(); } catch (Exception) { // not logged } }
Color GetColorFromImage(Point p) { try { Rect bounds = VisualTreeHelper.GetDescendantBounds(this); RenderTargetBitmap rtb = new RenderTargetBitmap((Int32)bounds.Width, (Int32)bounds.Height, 96, 96, PixelFormats.Default); rtb.Render(this); byte[] arr; PngBitmapEncoder png = new PngBitmapEncoder(); png.Frames.Add(BitmapFrame.Create(rtb)); using (var stream = new System.IO.MemoryStream()) { png.Save(stream); arr = stream.ToArray(); } BitmapSource bitmap = BitmapFrame.Create(new System.IO.MemoryStream(arr)); byte[] pixels = new byte[4]; CroppedBitmap cb = new CroppedBitmap(bitmap, new Int32Rect((int)p.X, (int)p.Y, 1, 1)); cb.CopyPixels(pixels, 4, 0); return(Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0])); } catch (Exception) { return(this.ColorBox.Color); } }
/// <summary> /// Gets the color of the pixel using the custom PixelColor . /// </summary> /// <param name="bitmapSource">The bitmap source.</param> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <returns>PixelColor</returns> /// <exception cref="PixelPicker.Helpers.OutOfBoundsException"></exception> public static PixelColor GetPixelColorUsingPixelColor(this BitmapImage bitmapSource, int x, int y) { if (bitmapSource == null) { throw new Exception(PixelPicker.BitmapImageException); } if (x < 0 || x > bitmapSource.PixelWidth - 1 || y < 0 || y > bitmapSource.PixelHeight - 1) { throw new OutOfBoundsException(); } var cb = new CroppedBitmap(bitmapSource, new Int32Rect(x, y, 1, 1)); byte[] pixels = new byte[4]; cb.CopyPixels(pixels, 4, 0); cb = null; var a = pixels[3]; var r = pixels[2]; var g = pixels[1]; var b = pixels[0]; return(new PixelColor(a, r, g, b)); }
private void Image_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { var AssociatedObject = this; // Retrieve the coordinate of the mouse position in relation to the supplied image. Point point = e.GetPosition(AssociatedObject); // Use RenderTargetBitmap to get the visual, in case the image has been transformed. var renderTargetBitmap = new RenderTargetBitmap((int)AssociatedObject.ActualWidth, (int)AssociatedObject.ActualHeight, 96, 96, PixelFormats.Default); renderTargetBitmap.Render(AssociatedObject); // Make sure that the point is within the dimensions of the image. if ((point.X <= renderTargetBitmap.PixelWidth) && (point.Y <= renderTargetBitmap.PixelHeight)) { // Create a cropped image at the supplied point coordinates. var croppedBitmap = new CroppedBitmap(renderTargetBitmap, new Int32Rect((int)point.X, (int)point.Y, 1, 1)); // Copy the sampled pixel to a byte array. var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); // Assign the sampled color to a SolidColorBrush and return as conversion. var SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); TextBox.Text = "#" + SelectedColor.ToString().Substring(3); Label.Background = new SolidColorBrush(SelectedColor); } }
/// <summary> /// Simply grab a 1*1 pixel from the current color image, and /// use that and copy the new 1*1 image pixels to a byte array and /// then construct a Color from that. /// </summary> private void CanvImage_MouseMove(object sender, MouseEventArgs e) { if (!IsMouseDown) { return; } try { CroppedBitmap cb = new CroppedBitmap(ColorImage.Source as BitmapSource, new Int32Rect((int)Mouse.GetPosition(CanvImage).X, (int)Mouse.GetPosition(CanvImage).Y, 1, 1)); byte[] pixels = new byte[4]; try { cb.CopyPixels(pixels, 4, 0); } catch (Exception) { //Ooops } //Ok now, so update the mouse cursor position and the SelectedColor ellipsePixel.SetValue(Canvas.LeftProperty, (double)(Mouse.GetPosition(CanvImage).X - 5)); ellipsePixel.SetValue(Canvas.TopProperty, (double)(Mouse.GetPosition(CanvImage).Y - 5)); CanvImage.InvalidateVisual(); SelectedColor = Color.FromArgb((byte)AlphaSlider.Value, pixels[2], pixels[1], pixels[0]); } catch (Exception) { //not much we can do } }
private void CanvasPanel_MouseMove(object sender, MouseEventArgs e) { if (!isMouseDown) { return; } else if (Mouse.GetPosition(CanvasPanel).X < 5 || Mouse.GetPosition(CanvasPanel).X > 165 || Mouse.GetPosition(CanvasPanel).Y < 5 || Mouse.GetPosition(CanvasPanel).Y > 165) { isMouseDown = false; } else if (Mouse.GetPosition(CanvImage).X < CanvImage.Width && Mouse.GetPosition(CanvImage).X >= 0 && Mouse.GetPosition(CanvImage).Y < CanvImage.Height && Mouse.GetPosition(CanvImage).Y >= 0) { CroppedBitmap cb = new CroppedBitmap(ColorImage.Source as BitmapSource, new Int32Rect((int)Mouse.GetPosition(CanvImage).X, (int)Mouse.GetPosition(CanvImage).Y, 1, 1)); byte[] pixels = new byte[4]; cb.CopyPixels(pixels, 4, 0); MoveEllipse(Mouse.GetPosition(CanvImage).X, Mouse.GetPosition(CanvImage).Y, Color.FromArgb(255, pixels[2], pixels[1], pixels[0])); CanvImage.InvalidateVisual(); SelectedColor = Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); UpdateTextBox(); } }
private void select_Color(object sender, MouseEventArgs e) { try { BitmapSource visual_BitmapSource = get_BitmapSource_of_Element(imgCubeWhite); CroppedBitmap cb = new CroppedBitmap(visual_BitmapSource, new Int32Rect((int)Mouse.GetPosition(imgCubeWhite).X, (int)Mouse.GetPosition(imgCubeWhite).Y, 1, 1)); byte[] pixels = new byte[4]; try { cb.CopyPixels(pixels, 4, 0); } catch (Exception) { } rectSelected.Fill = new SolidColorBrush(Color.FromRgb(pixels[2], pixels[1], pixels[0])); Properties.Settings.Default.colorR = PaintCanvas.DefaultDrawingAttributes.Color.R; Properties.Settings.Default.colorG = PaintCanvas.DefaultDrawingAttributes.Color.G; Properties.Settings.Default.colorB = PaintCanvas.DefaultDrawingAttributes.Color.B; Properties.Settings.Default.Save(); } catch (Exception) { } }
private static void CopyPixelsTo(BitmapSource sourceImage, Int32Rect sourceRoi, WriteableBitmap destinationImage, Int32Rect destinationRoi) { var croppedBitmap = new CroppedBitmap(sourceImage, sourceRoi); int stride = croppedBitmap.PixelWidth * (croppedBitmap.Format.BitsPerPixel / 8); var data = new byte[stride * croppedBitmap.PixelHeight]; croppedBitmap.CopyPixels(data, stride, 0); destinationImage.WritePixels(destinationRoi, data, stride, 0); }
// https://stackoverflow.com/a/25726349 public static void CopyPixelsTo(this BitmapSource sourceImage, Int32Rect sourceRoi, WriteableBitmap destinationImage, Int32Rect destinationRoi) { var croppedBitmap = new CroppedBitmap(sourceImage, sourceRoi); int stride = croppedBitmap.PixelWidth * (croppedBitmap.Format.BitsPerPixel / 8); var data = new byte[stride * croppedBitmap.PixelHeight]; // Is it possible to Copy directly from the sourceImage into the destinationImage? croppedBitmap.CopyPixels(data, stride, 0); destinationImage.WritePixels(destinationRoi, data, stride, 0); }
private byte[] ToGray8Array(BitmapSource source) { var gray = new FormatConvertedBitmap(source, PixelFormats.Gray8, null, 0); var rect = MakeTrimRect(); var trim = new CroppedBitmap(gray, rect); int stride = rect.Width; byte[] piexls = new byte[rect.Y * stride]; trim.CopyPixels(piexls, stride, 0); return(piexls); }
public RGBPixel GetPixel(Point position) { Image image = Canvas.Children[0] as Image; BitmapSource source = image.Source as BitmapSource; CroppedBitmap fragment = new CroppedBitmap(source, new Int32Rect((int)position.X, (int)position.Y, 1, 1)); byte[] color = new byte[source.Format.BitsPerPixel / 8]; fragment.CopyPixels(color, source.Format.BitsPerPixel / 8, 0); return(new RGBPixel(position, color[2], color[1], color[0])); }
public static Color GetColor(this BitmapSource source, Point point) { try { CroppedBitmap bitmap = new CroppedBitmap(source, new Int32Rect((int)Math.Round(point.X), (int)Math.Round(point.Y), 1, 1)); byte[] pixels = new byte[4]; bitmap.CopyPixels(pixels, pixels.Length, 0); return(Color.FromRgb(pixels[2], pixels[1], pixels[0])); } catch { return(new Color()); } }
void UpdateColorFromImage(int PositionX, int PositionY) { try { CroppedBitmap croppedBitmap = new CroppedBitmap(image_ColorSelector.Source as BitmapSource, new Int32Rect(PositionX, PositionY, 1, 1)); byte[] colorBytes = new byte[4]; croppedBitmap.CopyPixels(colorBytes, 4, 0); CustomColor = Color.FromArgb((byte)slider_Opacity.Value, colorBytes[2], colorBytes[1], colorBytes[0]); } catch { } }
Color PixelColor(ImageSource img, int PixelX, int PixelY) { /// pick the color to a byte array CroppedBitmap cb = new CroppedBitmap((BitmapSource)img, new Int32Rect(PixelX, PixelY, 1, 1)); byte[] pix = new byte[4]; cb.CopyPixels(pix, 4, 0); /// return the picked color return(Color.FromRgb(pix[2], pix[1], pix[0])); }
private Color GetColorFromImage(int i, int j) { var cb = new CroppedBitmap(image.Source as BitmapSource, new Int32Rect(i, j, 1, 1)); var color = new byte[4]; cb.CopyPixels(color, 4, 0); var colorFromImagePoint = Color.FromArgb(255, color[2], color[1], color[0]); return(colorFromImagePoint); }
/// <summary> /// 1*1 pixel copy is based on an article by Lee Brimelow /// http://thewpfblog.com/?p=62 /// </summary> private Color GetColorFromImage(int i, int j) { CroppedBitmap cb = new CroppedBitmap(image.Source as BitmapSource, new Int32Rect(i, j, 1, 1)); byte[] color = new byte[4]; cb.CopyPixels(color, 4, 0); Color Colorfromimagepoint = Color.FromArgb((byte)SdA.Value, color[2], color[1], color[0]); return(Colorfromimagepoint); }
public static System.Drawing.Bitmap CroppedBitmapToBitmap(CroppedBitmap bitmapSource) { var width = bitmapSource.PixelWidth; var height = bitmapSource.PixelHeight; var stride = width * ((bitmapSource.Format.BitsPerPixel + 7) / 8); var memoryBlockPointer = Marshal.AllocHGlobal(height * stride); bitmapSource.CopyPixels(new Int32Rect(0, 0, width, height), memoryBlockPointer, height * stride, stride); var bitmap = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, memoryBlockPointer); return(bitmap); }
public static Color GetPixelColor(this BitmapSource bitmapSource, double x, double y) { if (IsPositionOutsideBitmapBounds(bitmapSource, x, y)) { return(Colors.Transparent); } var croppedBitmap = new CroppedBitmap(bitmapSource, new Int32Rect((int)x, (int)y, 1, 1)); var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); return(Color.FromArgb(pixels[3], pixels[2], pixels[1], pixels[0])); }
private static Color GetColorFromPoint(Point point, BitmapImage bitmapSource) { if (point.X >= 0 && point.Y >= 0 && (int)point.X < (int)bitmapSource.Width && (int)point.Y < (int)bitmapSource.Height) { CroppedBitmap cb = new CroppedBitmap(bitmapSource, new Int32Rect((int)point.X, (int)point.Y, 1, 1)); byte[] color = new byte[4]; cb.CopyPixels(color, 4, 0); return(Color.FromArgb(255, color[2], color[1], color[0])); } else { return(Colors.White); } }
public Color GetPixel(BitmapSource bitmap, int x, int y) { Debug.Assert(bitmap != null); Debug.Assert(x >= 0); Debug.Assert(y >= 0); Debug.Assert(x < bitmap.PixelWidth); Debug.Assert(y < bitmap.PixelHeight); Debug.Assert(bitmap.Format.BitsPerPixel >= 24); CroppedBitmap cb = new CroppedBitmap(bitmap, new Int32Rect(x, y, 1, 1)); byte[] pixel = new byte[bitmap.Format.BitsPerPixel / 8]; cb.CopyPixels(pixel, bitmap.Format.BitsPerPixel / 8, 0); return(Color.FromRgb(pixel[2], pixel[1], pixel[0])); }
private void MainWindow_MouseMove(object sender, MouseEventArgs e) { System.Windows.Point point = e.GetPosition(this); //move info box System.Windows.Point oldPt = point; System.Windows.Point newPt = oldPt; double actualWidth = grdInfo.ActualWidth + 10; double actualHeight = grdInfo.ActualHeight + 10; newPt.X = (newPt.X + actualWidth) > this.ActualWidth ? this.ActualWidth - actualWidth : oldPt.X + 10; newPt.Y = (newPt.Y + actualHeight) > this.ActualHeight ? this.ActualHeight - actualHeight : oldPt.Y + 10; Canvas.SetLeft(grdInfo, newPt.X); Canvas.SetTop(grdInfo, newPt.Y); // Use RenderTargetBitmap to get the visual, in case the image has been transformed. var renderTargetBitmap = new RenderTargetBitmap((int)this.ActualWidth, (int)this.ActualHeight, 96, 96, PixelFormats.Default); renderTargetBitmap.Render(screenImage); // Make sure that the point is within the dimensions of the image. if ((point.X <= renderTargetBitmap.PixelWidth) && (point.Y <= renderTargetBitmap.PixelHeight)) { // Create a cropped image at the supplied point coordinates. var croppedBitmap = new CroppedBitmap(renderTargetBitmap, new Int32Rect((int)point.X, (int)point.Y - 10, 1, 1)); // Copy the sampled pixel to a byte array. var pixels = new byte[4]; croppedBitmap.CopyPixels(pixels, 4, 0); // Assign the sampled color to a SolidColorBrush and return as conversion. System.Drawing.Color clr = System.Drawing.Color.FromArgb(255, pixels[2], pixels[1], pixels[0]); txRGB.Text = $"R:{clr.R} G:{clr.G} B:{clr.B}"; txRGBHex.Text = $"#{clr.A:X2} {clr.R:X2} {clr.G:X2} {clr.B:X2}"; borderColor.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(clr.A, clr.R, clr.G, clr.B)); this._currentHexColor = $"#{clr.A:X2}" + $"{clr.R:X2}" + $"{clr.G:X2}" + $"{clr.B:X2}"; } }
public Task <IImageData> Convert( MemoryStream s, int bitDepth, string rawType, ImageMetaData metaData, CancellationToken token = default) { return(Task.Run(() => { using (MyStopWatch.Measure()) { FIBITMAP img; int left, top, imgWidth, imgHeight; FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_RAW; img = FreeImage.LoadFromStream(s, (FREE_IMAGE_LOAD_FLAGS)8, ref format); FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Width", out MetadataTag widthTag); FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Height", out MetadataTag heightTag); FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Left", out MetadataTag leftTag); FreeImage.GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, img, "Raw.Frame.Top", out MetadataTag topTag); left = int.Parse(leftTag.ToString()); top = int.Parse(topTag.ToString()); imgWidth = int.Parse(widthTag.ToString()); imgHeight = int.Parse(heightTag.ToString()); using (var memStream = new MemoryStream()) { FreeImage.SaveToStream(img, memStream, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_NONE); memStream.Position = 0; var decoder = new TiffBitmapDecoder(memStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); CroppedBitmap cropped = new CroppedBitmap(decoder.Frames[0], new System.Windows.Int32Rect(left, top, imgWidth, imgHeight)); ushort[] outArray = new ushort[cropped.PixelWidth * cropped.PixelHeight]; cropped.CopyPixels(outArray, 2 * cropped.PixelWidth, 0); FreeImage.UnloadEx(ref img); var imageArray = new ImageArray(flatArray: outArray, rawData: s.ToArray(), rawType: rawType); var data = new ImageData( imageArray: imageArray, width: cropped.PixelWidth, height: cropped.PixelHeight, bitDepth: bitDepth, isBayered: true, metaData: metaData); return Task.FromResult <IImageData>(data); } } })); }
public static WriteableBitmap CopyPixelsTo(BitmapSource sourceImage, Int32Rect sourceRoi, Int32Rect destinationRoi) { /*Taken from http://stackoverflow.com/questions/17750310/how-can-you-copy-part-of-a-writeablebitmap-to-another-writeablebitmap * and rerwitten to fit our needs. 28/10/2016 - 14:22 */ WriteableBitmap tmp = new WriteableBitmap(400, 200, 96.0, 96.0, PixelFormats.Bgr32, null); var croppedBitmap = new CroppedBitmap(sourceImage, sourceRoi); int stride = croppedBitmap.PixelWidth * (croppedBitmap.Format.BitsPerPixel / 8); var data = new byte[stride * croppedBitmap.PixelHeight]; // Is it possible to Copy directly from the sourceImage into the destinationImage? croppedBitmap.CopyPixels(data, stride, 0); tmp.WritePixels(destinationRoi, data, stride, 0); return(tmp); }
static public Color GetPixelColor(this Canvas canvas, Point p) { CroppedBitmap cb = new CroppedBitmap(canvas.ToBitmap(), new Int32Rect((int)p.X, (int)p.Y, 1, 1)); var pixels = new byte[4]; try { cb.CopyPixels(pixels, 4, 0); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(Color.FromScRgb(pixels[3], pixels[2], pixels[1], pixels[0])); }
private Color GetColour(BitmapSource bitmap, int position) { if (position >= bitmap.Width - 1) { position = (int)bitmap.Width - 2; } CroppedBitmap cb = new CroppedBitmap(bitmap, new Int32Rect(position, (int)this.VisualBounds.Height / 2, 1, 1)); byte[] tricolour = new byte[4]; cb.CopyPixels(tricolour, 4, 0); Color c = Color.FromRgb(tricolour[2], tricolour[1], tricolour[0]); return(c); }
private string DetectColor(CroppedBitmap bitmap) { var bytes = new Byte[82 * 82 * 4]; bitmap.CopyPixels(new Int32Rect(0, 0, 82, 82), bytes, 328, 0); for (var i = 0; i < 82 * 82; ++i) { if (bytes[i * 4] != 0 || bytes[i * 4 + 1] != 0 || bytes[i * 4 + 2] != 0) { return($"{bytes[i * 4]},{bytes[i * 4 + 1]},{bytes[i * 4 + 2]}"); } } return(null); }