Пример #1
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);
        }
Пример #2
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++;
                }
            }
        }