public boolean compress (Bitmap.CompressFormat format, int quality, OutputStream stream)
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).
|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.|
- true if successfully compressed to the specified stream.
BitmapFactory.Options options=new BitmapFactory.Options(); options.inSampleSize = 10;//here is your loss of quality: This will create an image of 1/10 in
width, If set to a value > 1, requests the decoder to subsample the original image, returning a smaller image to save memory.Any value <= 1 is treated the same as 1. Note: the decoder will try to fulfill this request, but the resulting bitmap may have different dimensions that precisely what has been requested. Also, powers of 2 are often faster/easier for the decoder to honor.Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length,options); fileOutputStream = new FileOutputStream( sdImageMainDirectory.toString() +"/"+fileName+".png"); BufferedOutputStream bos = new BufferedOutputStream( fileOutputStream); myImage.compress(CompressFormat.PNG, 100, bos); bos.flush(); bos.close();
You can only pass in a
Parcelable or a
Serializable object. Any object you want to pass via an
Intent must implement one of those interfaces. It’s recommended to implement
Parcelable there is a brief guide here: Pass by value Parameters using Parcelables.
Parcelable was designed for passing objects around, It requires a little more effort to use than using Java’s native serialization, but it’s way faster.
If you have more than one field to retrieve from a given Parcel, you must do this in the same order you put them in. FIFO
Intent i = new Intent(); i.putExtra("name_of_extra", myParcelableObject);Then you can pull them back out with getParcelableExtra():
Intent i = getIntent(); MyParcelable myParcelableObject = (MyParcelable) i.getParcelableExtra("name_of_extra");
- decodeByteArray(byte data, int offset, int length, BitmapFactory.Options opts) Decode an immutable bitmap from the specified byte array.
- decodeFile(String pathName, BitmapFactory.Options opts) Decode a file path into a bitmap.
- decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) Decode an input stream into a bitmap.
Intent intent = new Intent(“android.media.action.IMAGE_CAPTURE”);