Get a picture from a camera or album and plug it into ImageView

Source: Internet
Author: User

Get pictures from your camera or album and plug them into ImageView

Jump camera A line of code things

startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), 0);

Jump albums and crop, if you do not want to crop the clip to remove the code

Intent Intent = new Intent (intent.action_get_content);                    Intent.putextra ("Return-data", true);                    Intent.settype ("image/*");                    TODO tailoring Intent.putextra ("crop", "Circlecrop");                    TODO crop proportions Intent.putextra ("Aspectx", 1);                    Intent.putextra ("Aspecty", 1);                    TODO Crop Size Intent.putextra ("Outputx", 240);                    Intent.putextra ("Outputy", 240); Startactivityforresult (Intent, 1);

We jump through Startactivityforresult and select the picture and return to Onactivityforresult.

        if (Requestcode = = 0 | | requestcode = = 1) {if (data! = null) {Logutils.printlog ("Redwolf", "from phase            The data returned in the machine data+ "+ data.tostring ());            Photos taken from the album or Camera Logutils.printlog ("Redwolf", "data returned from the camera data+" + Data.getextras ());            Bitmap Mbitmap = (Bitmap) Data.getextras (). Get ("data");            File localimg = new file (Environment.getexternalstoragedirectory (). Getabsolutefile (), "SRCs");            if (!localimg.exists ()) {localimg.mkdirs ();            } File IconFile = new file (Localimg.getabsolutepath () + "/usericon.jpg");            if (iconfile.exists ()) {iconfile.delete ();            } outputstream out = null;            try {out = new FileOutputStream (iconfile);            } catch (FileNotFoundException e) {e.printstacktrace ();            }//2, write to local mbitmap.compress (Bitmap.CompressFormat.JPEG, +, out); 3. Plug into ImageViewZhong Mimageview.setimagebitmap (MBITMAP); 
Get pictures from your camera or album and plug them into ImageView

Get a picture from a camera or album and plug it into ImageView

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.