Bitmap bitmap = BitmapFactory.DecodeFile(filePath); using(FileOutputStream fos = new FileOutputStream(outputFile)) { bitmap.Compress(Bitmap.CompressFormat.Jpeg, 70, fos); }
Bitmap bitmap = BitmapFactory.DecodeFile(filePath); using(MemoryStream ms = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Png, 0, ms); byte[] imageData = ms.ToArray(); }In both examples, the Android.Graphics namespace is used to access the Bitmap and Compress classes. The CompressFormat enumeration is used to specify the compression format (JPEG or PNG) and the compression quality is set with an integer value. The package library used in these examples is the Android SDK's built-in graphics library.