Android: How to set the photo selected from gallery to a bitmap -
i asking user access gallery through code listener here:
intent photopickerintent = new intent(intent.action_pick); photopickerintent.settype("image/*"); startactivityforresult(photopickerintent, select_photo);
however, confused how set variable photo selected.
where put code set variable photo selected?
thanks :)
you can this.
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); // here need check if activity triggers image gallery. // if requestcode match load_image_results value. // if resultcode result_ok , there data know image picked. if (requestcode == load_image_results && resultcode == result_ok && data != null) { // let's read picked image data - uri uri pickedimage = data.getdata(); // let's read picked image path using content resolver string[] filepath = { mediastore.images.media.data }; cursor cursor = getcontentresolver().query(pickedimage, filepath, null, null, null); cursor.movetofirst(); string imagepath = cursor.getstring(cursor.getcolumnindex(filepath[0])); bitmapfactory.options options = new bitmapfactory.options(); options.inpreferredconfig = bitmap.config.argb_8888; bitmap bitmap = bitmapfactory.decodefile(imagepath, options); // bitmap // @ end remember close cursor or end runtimeexception! cursor.close(); } }
Comments
Post a Comment