Android Guides | Samples

Android.Graphics.Bitmap.Compress Method

Write a compressed version of the bitmap to the specified outputstream.

Syntax

[Android.Runtime.Register("compress", "(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z", "")]
public Boolean Compress (Bitmap+CompressFormat format, Int32 quality, Stream stream)

Parameters

format
The format of the compressed image
quality
Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting
stream
The outputstream to write the compressed data.

Remarks

Write a compressed version of the bitmap to the specified outputstream. If this returns true, the bitmap can be reconstructed by passing a corresponding inputstream to BitmapFactory.decodeStream(). Note: not all Formats support all bitmap configs directly, so it is possible that the returned bitmap from BitmapFactory could be in a different bitdepth, and/or may have lost per-pixel alpha (e.g. JPEG only supports opaque pixels).

[Android Documentation]

Requirements

Namespace: Android.Graphics
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1