Example #1
0
        /**
         * Extracts image pixels into byte array "pixels"
         */
        protected async Task GetImagePixels(IRandomAccessStream iRandomAccessStream)
        {
            Point pointWH = await WriteableBitmapExpansion.GetPixelWidthAndHeight(iRandomAccessStream);

            int w     = (int)pointWH.X;
            int h     = (int)pointWH.Y;
            int count = 0;

            byte[] tempByte = null;

            if ((w != width) ||
                (h != height)
                )
            {
                var bytes = await WriteableBitmapExpansion.ResizeBytes(iRandomAccessStream, width, height, BitmapInterpolationMode.Cubic);

                //imageIAStream = await WriteableBitmapExpansion.ConvertBytesToIRandomAccessStream(bytes);
                pixels   = new Byte[3 * width * height];
                pointWH  = new Point(width, height);
                tempByte = bytes;
            }
            else
            {
                pointWH = await WriteableBitmapExpansion.GetPixelWidthAndHeight(imageIAStream);

                pixels   = new Byte[3 * (int)pointWH.X * (int)pointWH.Y];
                tempByte = await WriteableBitmapExpansion.WriteableBitmapToBytes(imageIAStream);
            }

            for (int th = 0; th < pointWH.Y; th++)
            {
                for (int tw = 0; tw < pointWH.X; tw++)
                {
                    Color color = WriteableBitmapExpansion.GetPixel(tempByte, Convert.ToInt32(pointWH.X), tw, th);
                    pixels[count] = color.R;
                    count++;
                    pixels[count] = color.G;
                    count++;
                    pixels[count] = color.B;
                    count++;
                }
            }
        }