public boolean compress (Bitmap.CompressFormat format, int quality, OutputStream stream)

Added in API level 1

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 heigth and 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,

fileOutputStream = new FileOutputStream(
sdImageMainDirectory.toString() +"/"+fileName+".png");

BufferedOutputStream bos = new BufferedOutputStream(
myImage.compress(CompressFormat.PNG, 100, bos);

How can I pass an object of a custom type from one Activity to another using the putExtra() method of the class Intent?

You can only pass in aParcelable 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

Once you have your objects implement Parcelable it’s just a matter of putting them into your Intents withputExtra():

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");



当我们要得到原有的照片, 必须为拍照后的照片指定存放的路径地址,这个地址是在Intent中指定,方法是

Intent intent = new Intent(“”);

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: