public IImage Convert(ImageFormat imageFormat, int quality) {
     var ms = new MemoryStream();
     this.bitmap.Compress(Bitmap.CompressFormat.Jpeg, quality, ms);
     ms.Seek(0, SeekOrigin.Begin);
     this.bitmap.Dispose();
     this.bitmap = BitmapFactory.DecodeStream(ms);
     return this;
 }
        public IImage newImage(string fileName, ImageFormat format)
        {
            Bitmap.Config config = null;
            if (format == ImageFormat.RGB565)
                config = Bitmap.Config.RGB_565;
            else if (format == ImageFormat.ARGB4444)
                config = Bitmap.Config.ARGB_4444;
            else
                config = Bitmap.Config.ARGB_8888;

            var options = new BitmapFactory.Options();
            options.InPreferredConfig = config;


            InputStream @in = null;
            Bitmap bitmap;
            try
            {
                @in = assets.Open(assetsPrefix + fileName);
                bitmap = BitmapFactory.DecodeStream(@in, null, options);
                if (bitmap == null)
                    throw new SystemException("Couldn't load bitmap from asset '" + fileName + "'");
            }
            catch (IOException e)
            {
                throw new SystemException("Couldn't load bitmap from asset '" + fileName + "'");
            }
            finally
            {
                if (@in != null)
                {
                    try
                    {
                        @in.Close();
                    }
                    catch (IOException e)
                    {
                    }
                }
            }

            if (bitmap.GetConfig() == Bitmap.Config.RGB_565)
                format = ImageFormat.RGB565;
            else if (bitmap.GetConfig() == Bitmap.Config.ARGB_4444)
                format = ImageFormat.ARGB4444;
            else
                format = ImageFormat.ARGB8888;

            return new AndroidImage(bitmap, format);
        }
Example #3
-1
 public AndroidImage(Bitmap bitmap, ImageFormat format)
 {
     this.bitmap = bitmap;
     this.format = format;
 }