Android gets local pictures and displays pictures

Source: Internet
Author: User

Importjava.io.FileNotFoundException;ImportAndroid.content.ContentResolver;Importandroid.content.Intent;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.ImageView;ImportCOM.MAIKEFENGCHAO.DAIXU.R; Public classWritearticle_competerelayactivityextendsbaseactivity {PrivateImageView im_upload_img; @Override Public voidInitview (Bundle savedinstancestate) {Setcontentview (r.layout.view_write_competerelay); Im_upload_img=(ImageView) Findviewbyid (R.ID.WRITE_COMPETERELAY_COVER_IV); } @Overrideprotected voidSetlistener () {Im_upload_img.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {Intent Intent=NewIntent (); /*Turn on pictures screen type set to Image*/Intent.settype ("Image/*"); /*use intent.action_get_content this ACTION*/intent.setaction (intent.action_get_content); /*return to this screen after obtaining a photo*/Startactivityforresult (Intent,1);    }        }); } @Overrideprotected voidprocesslogic (Bundle saveinstancestate) {}//get local pictures@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        if(ResultCode = =RESULT_OK) {URI Uri=Data.getdata (); LOG.E ("uri", uri.tostring ()); Contentresolver CR= This. Getcontentresolver (); Try{Bitmap Bitmap=Bitmapfactory.decodestream (Cr.openinputstream (URI)); ImageView ImageView=(ImageView) Findviewbyid (R.ID.WRITE_COMPETERELAY_COVER_IV); /*set the bitmap to ImageView*/Imageview.setimagebitmap (bitmap); } Catch(FileNotFoundException e) {LOG.E ("Exception", E.getmessage (), E); }        }        Super. Onactivityresult (Requestcode, ResultCode, data); }}

Android gets local pictures and displays pictures

Related Article

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.