public static PixelMap GetPixelMap(Stream stream)
        {
            var decoder = BitmapRegionDecoder.NewInstance(stream, false);
            var bitmap  = decoder.DecodeRegion(new Rect(0, 0, decoder.Width, decoder.Height), null);

            var width  = bitmap.Width;
            var height = bitmap.Height;

            var source = new PixelMap(width, height);

            for (var y = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++)
                {
                    var pixel = bitmap.GetPixel(x, y);

                    source[x, y] = new Pixel
                    {
                        B = (byte)(pixel & 0x000000FF),
                        G = (byte)((pixel & 0x0000FF00) >> 8),
                        R = (byte)((pixel & 0x00FF0000) >> 16),
                        A = (byte)((pixel & 0xFF000000) >> 24)
                    };
                }
            }

            decoder.Recycle();

            return(source);
        }
Beispiel #2
0
        private Bitmap GetPokemonIcon(int id)
        {
            if (iconSetUri == null || GoOnTapApplication.Config.IconSetUri == null || iconSetUri.ToString() != GoOnTapApplication.Config.IconSetUri.ToString())
            {
                iconSetBitmapRegionDecoder?.Recycle();
                iconSetStream?.Dispose();

                try
                {
                    byte[] iconSetBytes = GoOnTapApplication.Config.IconSetBytes;

                    if (iconSetBytes != null)
                    {
                        iconSetStream = new MemoryStream(iconSetBytes);
                    }
                    else
                    {
                        iconSetStream = Context.ContentResolver.OpenInputStream(GoOnTapApplication.Config.IconSetUri);
                    }
                }
                catch (Exception e)
                {
                    GoOnTapApplication.Config.IconSetUri   = Config.DefaultIconSets.Values.First();
                    GoOnTapApplication.Config.IconSetBytes = null;

                    iconSetStream = Context.ContentResolver.OpenInputStream(GoOnTapApplication.Config.IconSetUri);
                }

                try
                {
                    iconSetBitmapRegionDecoder = BitmapRegionDecoder.NewInstance(iconSetStream, false);
                }
                catch
                {
                    return(null);
                }

                iconSetUri = GoOnTapApplication.Config.IconSetUri;
            }

            if (iconSetBitmapRegionDecoder == null)
            {
                return(null);
            }

            int x      = (id - 1) % 10;
            int y      = (id - 1) / 10;
            int width  = iconSetBitmapRegionDecoder.Width / 10;
            int height = width;

            try
            {
                return(iconSetBitmapRegionDecoder.DecodeRegion(new Rect(width * x, height * y, width * x + width, height * y + height), new BitmapFactory.Options()));
            }
            catch
            {
                return(null);
            }
        }
Beispiel #3
0
        private Bitmap CropAdjustPreview(System.String filePath)
        {
            BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.NewInstance(filePath, false);

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            BitmapFactory.DecodeFile(filePath, options);
            // setting up a cropping rect to grab only the top character info banner of the screenshot
            _width  = options.OutWidth / 4;
            _height = options.OutHeight / 2;
            Rect cropRect = new Rect(0, 0, _width, _height);

            // Decode bitmap with cropping rect set
            options.InJustDecodeBounds = false;
            return(bitmapRegionDecoder.DecodeRegion(cropRect, options));
        }
Beispiel #4
0
        private Bitmap CropToCharacterStatus(String filePath, int upperBound, int lowerBound)
        {
            BitmapRegionDecoder bitmapRegionDecoder = BitmapRegionDecoder.NewInstance(filePath, false);

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            BitmapFactory.DecodeFile(filePath, options);
            // setting up a cropping rect to grab only the top character info banner of the screenshot
            int  width    = options.OutWidth;
            int  height   = lowerBound + 1;
            Rect cropRect = new Rect(0, upperBound, width, height);

            // Decode bitmap with cropping rect set
            options.InJustDecodeBounds = false;
            return(bitmapRegionDecoder.DecodeRegion(cropRect, options));
        }