Example #1
0
        /**
         * Extracts image pixels into byte array "pixels"
         */
        protected async Task GetImagePixels(IRandomAccessStream iRandomAccessStream)
        {
            int w = (int)image.PixelWidth;
            int h = (int)image.PixelHeight;

            if ((w != width) ||
                (h != height)
                )
            {
                // create new image with right size/format
                //image.Resize(w, h, WriteableBitmapExtensions.Interpolation.Bilinear);
                //image = image.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
                image = await WriteableBitmapExpansion.Resize(image, iRandomAccessStream, width, height);

                //Graphics g = Graphics.FromImage( temp );
                //g.DrawImage(image, 0, 0);
                //image = temp;
                //g.Dispose();
            }

            /*
             *  ToDo:
             *  improve performance: use unsafe code
             */
            pixels = new Byte[3 * (int)image.PixelWidth * (int)image.PixelHeight];
            int count = 0;
            //WriteableBitmap tempBitmap = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
            //WriteableBitmap tempBitmap = image.Clone();
            //WriteableBitmap tempBitmap = WriteableBitmapExpansion.CloneWriteableBitmap(image);
            WriteableBitmap tempBitmap = WriteableBitmapExpansion.CopyWriteableBitmap(image);

            byte[] tempByte = WriteableBitmapExpansion.WriteableBitmapToBytes(image);
            for (int th = 0; th < image.PixelHeight; th++)
            {
                for (int tw = 0; tw < image.PixelWidth; tw++)
                {
                    //Color color = tempBitmap.GetPixel(tw, th);
                    //Color color = WriteableBitmapExpansion.GetPixel(tempBitmap, tw, th);
                    Color color = WriteableBitmapExpansion.GetPixel(tempByte, image.PixelWidth, tw, th);
                    pixels[count] = color.R;
                    count++;
                    pixels[count] = color.G;
                    count++;
                    pixels[count] = color.B;
                    count++;
                }
            }

            //pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
        }
Example #2
0
        public async Task <bool> AddFrame(IRandomAccessStream iRandomAccessStream)
        {
            if ((iRandomAccessStream == null) || !started || iRandomAccessStream.Size <= 0)
            {
                return(false);
            }
            bool ok = true;

            try
            {
                if (!sizeSet)
                {
                    // use first frame's size
                    Point pointWH = await WriteableBitmapExpansion.GetPixelWidthAndHeight(iRandomAccessStream);

                    SetSize((int)pointWH.X, (int)pointWH.Y);
                }
                imageIAStream = iRandomAccessStream;
                await GetImagePixels(iRandomAccessStream); // convert to correct format if necessary

                AnalyzePixels();                           // build color table & map pixels
                if (firstFrame)
                {
                    WriteLSD();     // logical screen descriptior
                    WritePalette(); // global color table
                    if (repeat >= 0)
                    {
                        // use NS app extension to indicate reps
                        WriteNetscapeExt();
                    }
                }
                WriteGraphicCtrlExt(); // write graphic control extension
                WriteImageDesc();      // image descriptor
                if (!firstFrame)
                {
                    WritePalette(); // local color table
                }
                WritePixels();      // encode and write pixel data
                firstFrame = false;
            }
            catch (IOException e)
            {
                ok = false;
            }

            return(ok);
        }
Example #3
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++;
                }
            }
        }