Android Call album photo control implement system control zoom cut picture

Source: Internet
Author: User

Android under if do processing picture software can call system control implementation Zoom cut picture very good effect today wrote a demo share to everyone

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;//photo
public static final int photozoom = 2; Scaling
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 Intent (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 Intent (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
Photo
if (Requestcode = = photohraph) {
Set file save path place it in the directory below.
File picture = new file (environment.getexternalstoragedirectory () + "/temp.jpg");
Startphotozoom (Uri.fromfile (picture));
}

if (data = = NULL)
Return

Read album Zoom picture
if (Requestcode = = Photozoom) {
Startphotozoom (Data.getdata ());
}
Processing results
if (Requestcode = = Photoresoult) {
Bundle extras = Data.getextras ();
if (extras! = null) {
Bitmap photo = extras.getparcelable ("Data");
Bytearrayoutputstream stream = new Bytearrayoutputstream ();
Photo.compress (Bitmap.CompressFormat.JPEG, (), stream);//(0-100) Compress files
Imageview.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 the ratio of width to height
Intent.putextra ("Aspectx", 1);
Intent.putextra ("Aspecty", 1);
Outputx Outputy is the cropped picture width high
Intent.putextra ("Outputx", 64);
Intent.putextra ("Outputy", 64);
Intent.putextra ("Return-data", true);
Startactivityforresult (Intent, Photoresoult);
}
}

<?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"
Android:adjustviewbounds= "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>

    • prev: ASP. C # image processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.