Android calls the System camera Method to Solve CPU compatibility problems

Source: Internet
Author: User
BTN. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {// use the camera app that comes with the system: Photograph intent = new intent (mediastore. action_image_capture); // create a file to save the imagefileuri = getoutputmediafileuri (media_type_image); // The intent value setting is related to the branch that will be entered in the onactivityresult, it is related to whether the data is null. If this parameter is specified, the later data is null // set the image file nameintent. putextra (mediastore. extra_output, fileu RI); startactivityforresult (intent, capture_image_activity_request_code) ;}}); @ overrideprotected void onactivityresult (INT requestcode, int resultcode, intent data) {super. onactivityresult (requestcode, resultcode, data); log. D (log_tag, "onactivityresult: requestcode:" + requestcode + ", resultcode:" + requestcode + ", data:" + data ); // if you are taking a photo if (capture_image_activity_request_code = requestcode) {Lo G. D (log_tag, "capture_image"); If (result_ OK = resultcode) {log. D (log_tag, "result_ OK"); // check if the result contains des a thumbnail bitmapif (Data! = NULL) {system. out. println ("1"); // log when no specific storage path is specified. D (log_tag, "data is not null, file on default position. "); // when the storage path is specified (intent. putextra (mediastore. extra_output, fileuri);) // image captured and saved to fileuri specified in the // intenttoast. maketext (this, "image saved to: \ n" + data. getdata (), toast. length_long ). show (); If (data. hasextra ("data") {bitmap thumbnail = data. getparcelableextra ("data"); system. out. println ("thumbnail:" + thumbnail); imageview. setimagebitmap (thumbnail) ;}} else {log. D (log_tag, "data is null, file saved on target position. "); // if there is no thumbnail image data, the image // will have been stored in the target output Uri. // resize the full image to fit in out Image view. system. out. println ("1"); int width = imageview. getwidth (); int Height = imageview. getheight (); system. out. println ("2"); bitmapfactory. options factoryoptions = new bitmapfactory. options (); factoryoptions. injustdecodebounds = true; bitmapfactory. decodefile (fileuri. getpath (), factoryoptions); int imagewidth = factoryoptions. outwidth; int imageheight = factoryoptions. outheight; // determine how much to scale down the imageint scalefactor = math. min (imagewidth/width, imageheight/height); // decode the image file into a bitmap sized to fill the // viewfactoryoptions. injustdecodebounds = false; factoryoptions. insamplesize = scalefactor; factoryoptions. inpurgeable = true; Bitmap bitmap = bitmapfactory. decodefile (fileuri. getpath (), factoryoptions); imageview. setimagebitmap (Bitmap) ;}} else if (resultcode = result_canceled) {// user canceled the image capture} else {// image capture failed, advise user }}// if the video is if (requestcode = capture_video_activity_request_code) {log. D (log_tag, "capture_video"); If (resultcode = result_ OK) {} else if (resultcode = result_canceled) {// user canceled the video capture} else {// video capture failed, advise user }}}

Source code download link: http://download.csdn.net/detail/msn465780/5771643
 

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.