An example of this article describes the Android implementation of image clipping method. Share to everyone for your reference, specific as follows:
Call the system's cropping tool to crop the photo album or photo.
Startactivityforresult is appropriate and some system action needs attention.
Package com.photosizing;
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;//camera 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 (Bundle 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 I
Ntent (Intent.action_pick, NULL);
Intent.setdataandtype (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, image_unspecified);
Startactivityforresult (Intent, photozoom);
}
}); Button1.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {Intent Intent = new I
Ntent (mediastore.action_image_capture); Intent.putextra (Mediastore.extra_output, Uri.fromfile) (New File (Environment.getexternalstoragedirectory (), "
Temp.jpg "));
Startactivityforresult (Intent, photohraph);
}
});
@Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (ResultCode = NONE)
Return
if (data = null) return; Photo if (Requestcode = = photohraph) {//Set file save path here in the directory with file picture = new File (EnviRonment.getexternalstoragedirectory () + "/temp.jpg");
Startphotozoom (Uri.fromfile (picture));
//Read photo album Zoom picture if (Requestcode = = 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, N, Stream);
(0-100) Compressed file Imageview.setimagebitmap (photo);
} super.onactivityresult (Requestcode, ResultCode, data);
The 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 wide-height proportional Intent.putextra ("Aspectx", 1);
Intent.putextra ("Aspecty", 1);
Outputx Outputy is a cropped picture of wide-high Intent.putextra ("Outputx", 64);
Intent.putextra ("Outputy", 64); Intent.putextra ("ReTurn-data ", true);
Startactivityforresult (Intent, Photoresoult);
}
}
XML file:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:orientation=" vertical "android:layout_width=" fill_parent "
android:layout_height=" Fill_parent ">
<textview android:layout_width=" fill_parent "android:layout_height=" Wrap_content "
android:text= "@string/hello"/>
<imageview android:id= "@+id/imageid"
True "Android:maxwidth=" 50dip "
android:maxheight=" 50dip "android:layout_width=" Wrap_content "
android: layout_height= "Wrap_content"/>
<button android:id= "@+id/btn_01" android:layout_height= "50dip"
Android:text= "album" Android:layout_width= "150dip"/>
<button android:id= "@+id/btn_02" Android:layout_ height= "50dip"
android:text= "photo" android:layout_width= "150dip"/>
</LinearLayout>
I hope this article will help you with the Android program.