In android, if you want to process images, you can call the system controls to achieve very good effects of scaling and cutting images. Today, I wrote a demo to share with you.
Package cn. m15.test; import java. io. byteArrayOutputStream; import java. io. file; import android. app. activity; import android. content. intent; import android. graphics. bitmap; import android.net. uri; import android. OS. bundle; import android. OS. environment; import android. provider. mediaStore; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. Widget. imageView; public class testActivity extends Activity {public static final int NONE = 0; public static final int PHOTOHRAPH = 1; // photograph public static final int PHOTOZOOM = 2; // scale public static final int PHOTORESOULT = 3; // result public static final String IMAGE_UNSPECIFIED = "image/*"; ImageView imageView = null; Button button0 = null; button button1 = null; @ Override public void onCreate (Bu Ndle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); imageView = (ImageView) findViewById (R. id. imageID); button0 = (Button) findViewById (R. id. btn_01); button1 = (Button) findViewById (R. id. btn_02); button0.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (Intent. ACTION_PICK, null); intent. setDataAnd Type (MediaStore. images. media. EXTERNAL_CONTENT_URI, IMAGE_UNSPECIFIED); startActivityForResult (intent, PHOTOZOOM) ;}}); button1.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE); intent. putExtra (MediaStore. EXTRA_OUTPUT, Uri. fromFile (new File (Environment. getExternalStorageDirectory (), "temp.jpg"); startAc TivityForResult (intent, PHOTOHRAPH) ;}}) ;}@ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {if (resultCode = NONE) return; // take a photo if (requestCode = PHOTOHRAPH) {// set the File storage path to File picture = new File (Environment. getExternalStorageDirectory () + "/temp.jpg"); startPhotoZoom (Uri. fromFile (picture);} if (data = null) return; // read the album zoom image if (requestCod E = PHOTOZOOM) {startPhotoZoom (data. getData ();} // processing result if (requestCode = PHOTORESOULT) {Bundle extras = data. getExtras (); if (extras! = Null) {Bitmap photo = extras. getParcelable ("data"); ByteArrayOutputStream stream = new ByteArrayOutputStream (); photo. compress (Bitmap. compressFormat. JPEG, 75, stream); // (0-100) compresses the imageView file. setImageBitmap (photo);} super. onActivityResult (requestCode, resultCode, data);} public void startPhotoZoom (Uri uri) {Intent intent = new Intent ("com. android. camera. action. CROP "); intent. setDataAndType (uri, IMAGE_UNSPECIFIED); intent. putExtra ("crop", "true"); // aspectX aspectY is a width-high ratio intent. putExtra ("aspectX", 1); intent. putExtra ("aspectY", 1); // outputX outputY is the width and height intent of the cropped image. putExtra ("outputX", 64); intent. putExtra ("outputY", 64); intent. putExtra ("return-data", true); startActivityForResult (intent, PHOTORESOULT );}}