Call the system camera and gallery to crop the picture

Source: Internet
Author: User
Tags dateformat

private static final int photo_request_takephoto = 1;//camera private static final int photo_request_gallery = 2;//Select from album private static final int photo_request_cut = 3;//result private File Tempfile = new file (Environment.getexternalstorag    EDirectory (), Getphotofilename ()); protected void Onactivityresult (int requestcode, int resultcode, Intent data) {switch (requestcode) {case            photo_request_takephoto://Call Startphotozoom (Uri.fromfile (tempfile)) when choosing to take a photo;        Break                Case photo_request_gallery://When you choose to obtain a picture from the local//make a non-null judgment, when we feel dissatisfied want to re-cut the time will not report an exception, the same as if (data! = NULL) {                System.out.println ("11================");            Startphotozoom (Data.getdata ());            } else {System.out.println ("================");        } break;                Case PHOTO_REQUEST_CUT://Returns the result if (data! = NULL)//Setpictoview (data);   Sentpictonext (data);         Break    } super.onactivityresult (Requestcode, ResultCode, data); }
Use the system current date to adjust the name of the photo    private String getphotofilename () {        Date date = new Date (System.currenttimemillis ());        SimpleDateFormat DateFormat = new SimpleDateFormat (                "' IMG ' _yyyymmdd_hhmmss");        return Dateformat.format (date) + ". jpg";    }

Call System Photo function:

Intent cameraintent = new Intent (                                    mediastore.action_image_capture);                            Specifies the storage path                            Cameraintent.putextra (Mediastore.extra_output,                                    uri.fromfile (tempfile)) of the photo after the camera is called.                            Startactivityforresult (cameraintent,                                    Photo_request_takephoto);

Call System album features:

Intent getalbum = new Intent (intent.action_get_content);                            Getalbum.settype ("image/*");                            Startactivityforresult (Getalbum, photo_request_gallery);

To invoke the system cropping feature:

private void Startphotozoom (Uri uri) {        Intent Intent = new Intent ("Com.android.camera.action.CROP");        Intent.setdataandtype (URI, "image/*");        Crop true is set to set the display of the view in the open intent can be clipped        intent.putextra ("Crop", "true");        Aspectx Aspecty is a proportional        Intent.putextra ("Aspectx", 1) of the wide height;        Intent.putextra ("Aspecty", 1);        Outputx,outputy is a wide-height        intent.putextra ("Outputx") of the cropped image        ; Intent.putextra ("Outputy");        Intent.putextra ("Return-data", true);        Intent.putextra ("Nofacedetection", true);        System.out.println ("22================");        Startactivityforresult (Intent, photo_request_cut);    }

Customize dialog box:

        Mdialog = new Alertdialog.builder (this, r.style.fullscreendialog)                . Create ();        if (Mdialog! = null &&!mdialog.isshowing ()) {            mdialog.show ();            Mdialog.setcontentview (R.LAYOUT.DIALOG_SELECT_IMGE);            Mdialog.setcanceledontouchoutside (FALSE);
}

Custom style:

<style name= "Fullscreendialog" parent= "Android:style/theme.dialog" >        <item name= "Android: Windownotitle ">true</item>        <item name=" Android:windowframe "> @null </item>        <item Name= "android:windowisfloating" >true</item>        <item name= "Android:windowistranslucent" >false </item>        <item name= "Android:background" > @android:color/transparent</item>        <item Name= "Android:windowbackground" > @android:color/transparent</item>        <item name= "Android: Backgrounddimenabled ">true</item>    </style>

Call the system camera and gallery to crop the picture

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.