public unsafe static void CopyPixels(this BitmapSource source, PixelColor[,] pixels, int stride, int offset)
        {
            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            byte[] pixel = new byte[height * stride];

            fixed(byte *buffer = &pixel[0])
            source.CopyPixels(
                new Int32Rect(0, 0, source.PixelWidth, source.PixelHeight),
                (IntPtr)(buffer + offset),
                width * height * sizeof(PixelColor),
                stride);

            Parallel.For(0, height, n =>
            {
                int m;

                for (m = 0; m < width; m++)
                {
                    pixels[m, n].Blue  = pixel[(n * width + m) * 4 + 0];
                    pixels[m, n].Green = pixel[(n * width + m) * 4 + 1];
                    pixels[m, n].Red   = pixel[(n * width + m) * 4 + 2];
                    pixels[m, n].Alpha = pixel[(n * width + m) * 4 + 3];
                }
            });
        }
Esempio n. 2
0
        public static void CopyPixelsOverride(this BitmapSource source, PixelColor[,] pixels, int stride, int offset)
        {
            var height     = source.PixelHeight;
            var width      = source.PixelWidth;
            var pixelBytes = new byte[height * width * 4];

            source.CopyPixels(pixelBytes, stride, 0);
            int y0 = offset / width;
            int x0 = offset - width * y0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    pixels[x + x0, y + y0] = new PixelColor
                    {
                        Blue  = pixelBytes[(y * width + x) * 4 + 0],
                        Green = pixelBytes[(y * width + x) * 4 + 1],
                        Red   = pixelBytes[(y * width + x) * 4 + 2],
                        Alpha = pixelBytes[(y * width + x) * 4 + 3],
                    }
                }
            }
            ;
        }
Esempio n. 3
0
        public MapState[,] GetExplorationMap(IPixelComparer pixelComparer, PixelColor[,] source)
        {
            int width  = source.GetLength(0);
            int height = source.GetLength(1);

            var cellState = new MapState[width, height];

            // TODO: Parallelise
            // TODO: Refactor into Strategy pattern.
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    var newColor = source[x, y]
                                   .ToColor();

                    var open = pixelComparer
                               .IsOpen(newColor);

                    cellState[x, y] = open ?
                                      MapState.AsOpen() :
                                      MapState.AsClosed();
                }
            }

            return(cellState);
        }
Esempio n. 4
0
        public static Texture2D Texture2DFromPixelsTopLeft(PixelColor[,] pixels)
        {
            int ImgH = pixels.GetLength(0);
            int ImgW = pixels.GetLength(1);

            var texture2D = new Texture2D(ImgW, ImgH);

            var c = new Color32[pixels.Length];

            for (var i = 0; i < ImgH; i++)
            {
                for (var j = 0; j < ImgW; j++)
                {
                    var p   = pixels[i, j];
                    var col = new Color32(p.Red, p.Green, p.Blue, p.Alpha);
                    c[i * ImgW + j] = col;
                }
            }

            texture2D.SetPixels32(c);
            // DPI must be same as original image, otherwise rescaling display can occur (NoScaling)
            //var wBitmap = new WriteableBitmap(ImgW, ImgH, DpiX, DpiY, System.Windows.Media.PixelFormats.Bgra32, null);

            // 1) copy PixelsOut to bitmap
            // qq to do: ImgW or ImgW-1 in rect??; stride=0 seems to work ...
            //Int32Rect sourceRect = new Int32Rect(0, 0, ImgW, ImgH);

            //wBitmap.WritePixels(sourceRect, PixelsTopLeft, ImgW * 4, 0);

            // 2) set Image1.Source=wBitmap; e.g. handle change source in Bitmap.
            return(texture2D);
        }
Esempio n. 5
0
            public GameGrid(int width, int height)
            {
                this.width  = width;
                this.height = height;

                grid = PixelColor.GetSingleColorMap(width, height, PixelColor.BLACK);
            }
        public unsafe static void PutPixels(WriteableBitmap bitmap, PixelColor[,] pixels, int x, int y)
        {
            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);
            var stride = width * ((bitmap.Format.BitsPerPixel + 7) / 8);

            byte[] pixel = new byte[height * stride];

            Parallel.For(0, height, n =>
            {
                int m;

                for (m = 0; m < width; m++)
                {
                    pixel[(n * width + m) * 4 + 0] = pixels[m, n].Blue;
                    pixel[(n * width + m) * 4 + 1] = pixels[m, n].Green;
                    pixel[(n * width + m) * 4 + 2] = pixels[m, n].Red;
                    pixel[(n * width + m) * 4 + 3] = pixels[m, n].Alpha;
                }
            });

            fixed(byte *buffer = &pixel[0])
            bitmap.WritePixels(
                new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight),
                (IntPtr)(buffer),
                width * height * sizeof(PixelColor),
                stride);
        }
        PixelColor Dilation_Crossdot(PixelColor[,] temp, int x, int y, int ksize)
        {
            int  k, l, m, n;
            byte checkpixel_R = 0;
            byte checkpixel_G = 0;
            byte checkpixel_B = 0;
            var  weidth       = temp.GetLength(0);
            var  height       = temp.GetLength(1);

            for (int i = 0; i < ksize; i++)
            {
                k = (i - ksize / 2);
                for (int j = 0; j < ksize; j++)
                {
                    l            = (j - ksize / 2);
                    m            = ((x - k) >= 0 && (x - k) < weidth) ? (x - k) : x + k;
                    n            = ((y - l) >= 0 && (y - l) < height) ? (y - l) : y + l;
                    checkpixel_R = Math.Max(checkpixel_R, temp[m, n].Red);
                    checkpixel_G = Math.Max(checkpixel_G, temp[m, n].Green);
                    checkpixel_B = Math.Max(checkpixel_B, temp[m, n].Blue);
                }
            }
            return(new PixelColor {
                Blue = checkpixel_B, Green = checkpixel_G, Red = checkpixel_R, Alpha = temp [x, y].Alpha
            });
        }
Esempio n. 8
0
        void GenerateMap(Uri uri)
        {
            ImageDataLoader imageDataLoader = new ImageDataLoader(uri);

            PixelColor[,] pixels = imageDataLoader.GetPixels();
            int       countX    = pixels.GetLength(0);
            int       countZ    = pixels.GetLength(1);
            int       startX    = 0;
            int       startZ    = 0;
            int       gridStep  = 100;
            double    minY      = -300;
            double    maxY      = 3000;
            ImageData imageData = new ImageData(
                new DoubleCollection(countX),
                new DoubleCollection(countZ),
                new DoubleCollection(countX * countZ)
                );
            bool fullZ = false;

            for (int i = 0; i < countX; i++)
            {
                imageData.XArguments.Add(startX + i * gridStep);
                for (int j = 0; j < countZ; j++)
                {
                    if (!fullZ)
                    {
                        imageData.YArguments.Add(startZ + j * gridStep);
                    }
                    double value = GetValue(pixels[i, j], minY, maxY);
                    imageData.Values.Add(value);
                }
                fullZ = true;
            }
            ImageData = imageData;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog
            {
                Filter      = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*",
                FilterIndex = 2
            };

            of.ShowDialog();
            String filename = of.FileName.ToString();

            if (filename != "")
            {
                try
                {
                    read_image      = new BitmapImage(new Uri(of.FileName, UriKind.RelativeOrAbsolute));
                    image1.Source   = read_image;
                    bitmapImage     = read_image.Clone();
                    width           = bitmapImage.PixelWidth;
                    height          = bitmapImage.PixelHeight;
                    stride          = (width * bitmapImage.Format.BitsPerPixel + 7) / 8;
                    pixel_Closing   = GetPixels(bitmapImage);
                    pixel_ori       = (PixelColor[, ])pixel_Closing.Clone();
                    writeableBitmap = new WriteableBitmap(width, height, bitmapImage.DpiX, bitmapImage.DpiY, PixelFormats.Bgra32, bitmapImage.Palette);
                    Dilation(ref pixel_Closing, 7);
                    Erosion(ref pixel_Closing, 7);
                    hsv_image = Transfer_to_HSV(pixel_Closing);
                }
                catch { }
            }

            //button2_Click();
        }
Esempio n. 10
0
			protected override void ReadBlock(SimpleBinaryStream stream, ref PixelColor[,] cache, int blockX)
			{
				blockX *= 4;
				PixelColor[] baseColor = new PixelColor[4];
				ushort color0, color1;
				baseColor[0] = GetColorFromRGB565(color0 = stream.ReadUInt16());
				baseColor[1] = GetColorFromRGB565(color1 = stream.ReadUInt16());
				if (color0 > color1)
				{
					// baseColor[2] = (baseColor[0] * 2 + baseColor[1]) / 3;
					baseColor[2] = PixelColor.MAD(baseColor[0], 2, baseColor[1], 3);
					baseColor[3] = PixelColor.MAD(baseColor[1], 2, baseColor[0], 3);
				}
				else
				{
					baseColor[2] = PixelColor.AVG(baseColor[0], baseColor[1]);
					baseColor[3] = new PixelColor(0, 0, 0, 1f);
				}

				for (int y = 0; y < 4; y++)
				{
					byte index = stream.ReadByte();
					cache[y, blockX + 0] = baseColor[(index >> 0) & 0x3];
					cache[y, blockX + 1] = baseColor[(index >> 2) & 0x3];
					cache[y, blockX + 2] = baseColor[(index >> 4) & 0x3];
					cache[y, blockX + 3] = baseColor[(index >> 6) & 0x3];
				}
			}
Esempio n. 11
0
        private PixelColor[,] DrawNoiseMap(IAlgorithmTarget target, PixelColor[,] source, NoiseMap noiseMap, PixelColor baseColor, PixelColor shapeColor, double cutoffValue)
        {
            var   random         = new Random();
            float random1        = (float)random.NextDouble() * random.Next(-1, 1);
            float random2        = (float)random.NextDouble() * random.Next(-1, 1);
            float upperBounds    = Math.Max(random1, random2);
            float lowerBounds    = Math.Min(random1, random2);
            float boundsDistance = upperBounds - lowerBounds;

            target.AlgorithmPixels.ForEach
            (
                pixel =>
            {
                var position = pixel.Position;
                int x        = (int)position.X, y = (int)position.Y;
                var value    = noiseMap.GetValue(x, y);
                value        = value.Clamp(lowerBounds, upperBounds);
                var distanceFromLowerBounds = value - lowerBounds;
                var offsetValue             = (boundsDistance == 0.0f) ? 0.0f : distanceFromLowerBounds / boundsDistance;
                //source[y, x] = ((value * 100) >= cutoffValue) ? shapeColor.Blend(baseColor, value) : baseColor;
                source[y, x] = shapeColor.Blend(baseColor, offsetValue);
            }
            );
            return(source);
        }
        private void CopyPixels(BitmapSource source, PixelColor[,] pixels, int stride, int offset)
        {
            var height = source.PixelHeight;
            var width  = source.PixelWidth;

            var pixelBytes = new byte[height * width * 4];

            source.CopyPixels(pixelBytes, stride, 0);

            int y0 = offset / width;
            int x0 = offset - width * y0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var b = pixelBytes[(y * width + x) * 4 + 0];
                    var g = pixelBytes[(y * width + x) * 4 + 1];
                    var r = pixelBytes[(y * width + x) * 4 + 2];
                    var a = pixelBytes[(y * width + x) * 4 + 3];

                    pixels[x + x0, y + y0] = new PixelColor(r, g, b, a);
                }
            }
        }
Esempio n. 13
0
        private PixelColor[,] BitmapSourceToArray(BitmapSource source)
        {
            // Stride = (width) x (bytes per pixel)
            int stride = (int)source.PixelWidth * (source.Format.BitsPerPixel / 8);

            byte[] pixels = new byte[(int)source.PixelHeight * stride];
            source.CopyPixels(pixels, stride, 0);
            var pixelLIst = pixels.ToList();
            int width     = source.PixelWidth;
            int height    = source.PixelHeight;
            List <PixelColor> pixelColorsList = new List <PixelColor>();

            for (int i = 0; i < pixelLIst.Count; i += 4)
            {
                List <byte> items = pixelLIst.Skip(i).Take(4).ToList();
                pixelColorsList.Add(new PixelColor(items));
            }
            originalPic = new PixelColor[width, height];
            int vertikal   = 0;
            int horizontal = 0;

            foreach (var item in pixelColorsList)
            {
                originalPic[horizontal, vertikal] = item;
                horizontal++;
                if (horizontal >= width)
                {
                    horizontal = 0;
                    vertikal++;
                }
            }
            return(originalPic);
        }
Esempio n. 14
0
 public PixelColor[,] CopyPixels()
 {
     lock (this)
     {
         if (this.Pixels == null)
         {
             BitmapSource source = this._imageBitmap;
             if (source.Format != PixelFormats.Bgra32)
             {
                 source = new FormatConvertedBitmap(source, PixelFormats.Bgra32, null, 0);
             }
             PixelColor[,] pixels = new PixelColor[source.PixelWidth, source.PixelHeight];
             int      stride       = source.PixelWidth * ((source.Format.BitsPerPixel + 7) / 8);
             GCHandle pinnedPixels = GCHandle.Alloc(pixels, GCHandleType.Pinned);
             source.CopyPixels(
                 new Int32Rect(0, 0, source.PixelWidth, source.PixelHeight),
                 pinnedPixels.AddrOfPinnedObject(),
                 pixels.GetLength(0) * pixels.GetLength(1) * 4,
                 stride);
             pinnedPixels.Free();
             Pixels = pixels;
         }
         return(Pixels);
     }
 }
Esempio n. 15
0
        private static void Validate(PixelColor[,] pixels)
        {
            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    // Check the image is loaded correctly, but note that
                    // what constitutes a closed pixel will change.
                    var closedPixel = x == 4 || x == 5 || y == 4 || y == 5;
                    var pixel       = pixels[x, y];

                    bool r;
                    bool g;
                    bool b;

                    if (closedPixel)
                    {
                        r = pixel.Red == 0;
                        g = pixel.Green == 0;
                        b = pixel.Blue == 0;
                    }
                    else
                    {
                        r = pixel.Red == 255;
                        g = pixel.Green == 255;
                        b = pixel.Blue == 255;
                    }

                    Assert.IsTrue(r && g && b, "Pixel Invalid");
                }
            }
        }
Esempio n. 16
0
        public static bool CompareImages(PixelColor[,] p1, PixelColor[,] p2)
        {
            if (p1.GetLength(0) != p2.GetLength(0))
            {
                return(false);
            }

            long red = 0, green = 0, blue = 0;

            for (int i = 1; i < p1.GetLength(0) - 1; i++)
            {
                for (int j = 1; j < p1.GetLength(1) - 1; j++)
                {
                    PixelColor color   = p1[i, j];
                    PixelColor average = getAverageColor(p2, i, j);

                    PixelColor diff = color - average;
                    red   += diff.Red;
                    green += diff.Green;
                    blue  += diff.Blue;
                }
            }
            red   = (int)((float)red / p1.Length);
            green = (int)((float)green / p1.Length);
            blue  = (int)((float)blue / p1.Length);

            float total = (float)(red + green + blue) / 3f;

            return(total < 6);
        }
        public TableAppImage()
        {
            //Image image = Image.FromFile(@"D:\Projekte\Visual Studio\MatrixLedTableController\MatrixLedTableController\bin\Debug\eye.jpg");
            //image = ResizeImage(image, Program.TableWidth, Program.TableHeight);

            /*
             * map = new PixelColor[image.Width, image.Height];
             * using (Bitmap bmp = new Bitmap(image))
             * {
             *  for(int x = 0; x < image.Width; x++)
             *  {
             *      for(int y = 0; y < image.Height; y++)
             *      {
             *          Color clr = bmp.GetPixel(x, y);
             *          int red = clr.R;
             *          int green = clr.G;
             *          int blue = clr.B;
             *
             *          map[x, y] = new PixelColor(red, green, blue);
             *      }
             *  }
             * }
             */

            map = PixelColor.GetSingleColorMap(Program.TableWidth, Program.TableHeight, PixelColor.RED);
        }
Esempio n. 18
0
        public static void PutPixels(this WriteableBitmap bitmap, PixelColor[,] pixels, int x, int y)
        {
            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            bitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, width * 4, x, y);
        }
Esempio n. 19
0
			protected override void ReadBlock(SimpleBinaryStream stream, ref PixelColor[,] cache, int blockX)
			{
				base.ReadBlock(stream, ref cache, blockX);
				DXT5Reader.ReadBC3AlphaBlock(stream.ReadInt64(), ref cache, blockX * 4, (ref PixelColor pixel, float value) =>
				{
					pixel.G = value;
				});
			}
Esempio n. 20
0
        public static MapState[,] ExploreMap(PixelColor[,] pixels)
        {
            var comparer   = new TolerancePixelComparer(20, Color.FromRgb(255, 255, 255));
            var mapBuilder = new ExplorationMapBuilder();
            var map        = mapBuilder.GetExplorationMap(comparer, pixels);

            return(map);
        }
Esempio n. 21
0
        private bool isUnknown(PixelColor[,] pixels)
        {
            if (compareColor(pixels[10, 10], new PixelColor(99, 176, 255), colorDelta))
            {
                return(true);
            }

            return(false);
        }
        public void CleanUp()
        {
            currentApp = null;

            //Clear the screen
            PixelColor[,] clear = PixelColor
                                  .GetSingleColorMap(Program.TableWidth, Program.TableHeight, PixelColor.BLACK);
            Program.tableRenderer.Render(clear);
        }
Esempio n. 23
0
 public unsafe static void CopyPixels(BitmapSource source, PixelColor[,] pixels, int stride, int offset)
 {
     fixed(PixelColor *buffer = &pixels[0, 0])
     source.CopyPixels(
         new Int32Rect(0, 0, source.PixelWidth, source.PixelHeight),
         (IntPtr)(buffer + offset),
         pixels.GetLength(0) * pixels.GetLength(1) * sizeof(PixelColor),
         stride);
 }
Esempio n. 24
0
			protected override void ReadBlock(SimpleBinaryStream stream, ref PixelColor[,] cache, int blockX)
			{
				long alphaData = stream.ReadInt64();
				base.ReadBlock(stream, ref cache, blockX);
				ReadBC3AlphaBlock(alphaData, ref cache, blockX * 4, (ref PixelColor pixel, float value) =>
				{
					pixel.A = value;
				});
			}
 public DanilSegmentation(PictureBox mainPictureBox)
 {
     mainImage = new Bitmap(mainPictureBox.Image);
     imagePixelColor = new PixelColor[mainImage.Width, mainImage.Height];
     whichSegment = new int[mainImage.Width, mainImage.Height];
     used = new bool[mainImage.Width, mainImage.Height];
     numberOfSegments = 1;
     imageToMatrix();
     setWhichSegment();
 }
 public static void RemoveWeakColors()
 {
     PixelColor[,] pixels = CurrentState.currentPixels;
     for (int i = 0; i < pixels.GetLength(0); i++)
     {
         for (int j = 0; j < pixels.GetLength(1); j++)
         {
             CurrentState.currentPixels[i, j].RemoveWeakColors();
         }
     }
 }
Esempio n. 27
0
        public BlockParser()
        {
            imgGuess = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/one.png")));
            imgTwo   = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/three.png")));
            imgFour  = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/five.png")));
            imgSix   = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/seven.png")));
        }
Esempio n. 28
0
        public BlockParser()
        {
            imgGuess = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/one.png")));
            imgTwo = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/three.png")));
            imgFour = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/five.png")));
            imgSix = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/MinesweeperSolver;component/Images/seven.png")));
        }
        public static void IntensifyHighBitsReduceLowBits(byte amount)
        {
            PixelColor[,] pixels = CurrentState.currentPixels;

            for (int i = 0; i < pixels.GetLength(0); i++)
            {
                for (int j = 0; j < pixels.GetLength(1); j++)
                {
                    pixels[i, j].IntensifyHighBitsReduceLowBits(amount);
                }
            }
        }
Esempio n. 30
0
        private void CreateNewEmptyBitmap()
        {
            //finde die groessten Seitenlaengen
            double distanceA  = Distance(pA, pB);
            double distanceB  = Distance(pB, pC);
            double distanceC  = Distance(pC, pD);
            double distanceD  = Distance(pD, pA);
            double horizontal = Math.Max(distanceA, distanceC);
            double vertical   = Math.Max(distanceB, distanceD);

            resultPic = new PixelColor[(int)horizontal, (int)vertical];
        }
        public static void ToOneBit()
        {
            PixelColor[,] pixels = CurrentState.currentPixels;

            for (int i = 0; i < pixels.GetLength(0); i++)
            {
                for (int j = 0; j < pixels.GetLength(1); j++)
                {
                    pixels[i, j].ToOneBit();
                }
            }
        }
        public async Task <TextureProfile> GenerateTextureProfileAsync(PixelColor[,] pixelColors, Color transparencyColor, IDialogContext dialogContext, ITaskContext ourTaskContext)
        {
            ourTaskContext.UpdateMessage("Starting processing of image");
            PixelsSource pixelsSource = null;
            await dialogContext.AddTask
            (
                (taskContext) =>
            {
                taskContext.UpdateMessage("Converting pixels");
                pixelsSource = PixelsSource.FromPixelColors(pixelColors);
                taskContext.UpdateProgress(100);
            }
            );

            var pixelGroups = pixelsSource.PixelsList.GroupBy(pixel => pixel.PixelColor);

            var    tasks = new List <Task>();
            var    modifiedPixelGroups = new List <List <PixelBlob> >();
            object mutex = new object();

            foreach (var pixelGroup in pixelGroups)
            {
                if (transparencyColor.IsEqualToPixelColor(pixelGroup.Key))
                {
                    continue;
                }
                tasks.Add
                (
                    dialogContext.AddTask
                    (
                        (taskContext) =>
                {
                    var result = this.ProcessPixelGroup(pixelGroup, pixelsSource, taskContext);
                    lock (mutex)
                    {
                        modifiedPixelGroups.Add(result);
                    }
                }
                    )
                );
            }
            Task.WaitAll(tasks.ToArray());
            ourTaskContext.UpdateProgress(100);
            var texture = new TextureProfile()
            {
                TransparencyColor = transparencyColor.ToPixelColor(),
                Blobs             = modifiedPixelGroups.SelectMany(x => x).ToList()
            };

            return(texture);
        }
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            var fd = new OpenFileDialog();
            BitmapSource image = null;
            if (fd.ShowDialog() == true)
            {
                image = new BitmapImage(new Uri(fd.FileName));
                currentFile = System.IO.Path.GetFileNameWithoutExtension(fd.FileName);
            }
            else
            {
                return;
            }

            Image.Source = image;
            pixels = GetPixels(image);
            UpdateAll();
        }
Esempio n. 34
0
 public PixelColor[,] CopyPixels()
 {
     lock (this)
     {
         if (this.Pixels == null)
         {
             BitmapSource source = this._imageBitmap;
             if (source.Format != PixelFormats.Bgra32)
                 source = new FormatConvertedBitmap(source, PixelFormats.Bgra32, null, 0);
             PixelColor[,] pixels = new PixelColor[source.PixelWidth, source.PixelHeight];
             int stride = source.PixelWidth * ((source.Format.BitsPerPixel + 7) / 8);
             GCHandle pinnedPixels = GCHandle.Alloc(pixels, GCHandleType.Pinned);
             source.CopyPixels(
               new Int32Rect(0, 0, source.PixelWidth, source.PixelHeight),
               pinnedPixels.AddrOfPinnedObject(),
               pixels.GetLength(0) * pixels.GetLength(1) * 4,
                   stride);
             pinnedPixels.Free();
             Pixels = pixels;
         }
         return Pixels;
     }
 }