Android System Photo source

Source: Internet
Author: User

A personal snapshot of the Android system: a custom picture-taking path, and a thumbnail image that is processed directly using Android

Pay special attention to the first way to increase the SDK read and Write permissions: <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> directly under the source code

1  PackageCom.example.camerademo;2 3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 Importjava.io.FileNotFoundException;6 Importjava.io.IOException;7 8 Importandroid.app.Activity;9 Importandroid.content.Intent;Ten ImportAndroid.graphics.Bitmap; One Importandroid.graphics.BitmapFactory; A ImportAndroid.net.Uri; - ImportAndroid.os.Bundle; - Importandroid.os.Environment; the ImportAndroid.provider.MediaStore; - ImportAndroid.view.View; - ImportAndroid.widget.ImageView; -  +  Public classMainactivityextendsActivity { -      +      Public Static Final intRequest_camera_code = 100; A      Public Static Final intRequest_camera_auto = 101; at ImageView mIv; - String Path; -      - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); in Setcontentview (r.layout.activity_main); -MIv =(ImageView) Findviewbyid (R.ID.IV); toPath = environment.getexternalstoragedirectory () + "/" + "temp.jpg"; +     } -      the      Public voidDoClick1 (View v) { *Intent Intent =NewIntent (mediastore.action_image_capture); $Intent.putextra (Mediastore.extra_output, Uri.fromfile (NewFile (path ));Panax Notoginseng Startactivityforresult (Intent, request_camera_code); -     } the      Public voidDoClick2 (View v) { +Intent Intent =NewIntent (mediastore.action_image_capture); A Startactivityforresult (Intent, request_camera_auto); the     } +      -      $      $ @Override -     protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { -         Super. Onactivityresult (Requestcode, ResultCode, data); the         if(ResultCode = =RESULT_OK) { -             if(Requestcode = =Request_camera_code) {WuyiFileInputStream FIS =NULL; the                 Try { -FIS =NewFileInputStream (path); WuBitmap Bitmap =Bitmapfactory.decodestream (FIS); -                     if(Bitmap! =NULL) { About Miv.setimagebitmap (bitmap); $                     } -}Catch(FileNotFoundException e) { -                     //TODO auto-generated Catch block - e.printstacktrace (); A}finally{ +                     if(FIS! =NULL) { the                         Try { - fis.close (); $}Catch(IOException e) { the                             //TODO auto-generated Catch block the e.printstacktrace (); the                         } the                     } -                 } in                  the}Else if(Requestcode = =Request_camera_auto) { theBundle bundle =Data.getextras (); AboutBitmap Bitmap = (Bitmap) bundle.get ("Data")); the                 if(Bitmap! =NULL) { the Miv.setimagebitmap (bitmap); the                 } +             } -         } the         Bayi     } the      the}
1<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"2Xmlns:tools= "Http://schemas.android.com/tools"3Android:layout_width= "Match_parent"4android:layout_height= "Match_parent"5tools:context= "${relativepackage}.${activityclass}" >6 7<TextView8Android:id= "@+id/textview1"9Android:layout_width= "Wrap_content"Tenandroid:layout_height= "Wrap_content" Oneandroid:text= "@string/hello_world"/> A  -<Button -Android:id= "@+id/startcamera" theandroid:onclick= "DoClick1" -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" -android:layout_below= "@+id/textview1" +Android:layout_centerhorizontal= "true" -android:layout_margintop= "17DP" +android:text= "Startcamera_custome_address"/> A  at<ImageView -Android:id= "@+id/iv" -Android:layout_width= "Wrap_content" -android:layout_height= "Wrap_content" -android:layout_alignleft= "@+id/startcamera" -Android:layout_centervertical= "true" inandroid:layout_marginleft= "32DP"/> -  to<Button +Android:id= "@+id/button1" -android:onclick= "DoClick2" theAndroid:layout_width= "Wrap_content" *android:layout_height= "Wrap_content" $android:layout_alignleft= "@+id/startcamera"Panax Notoginsengandroid:layout_below= "@+id/startcamera" -android:layout_margintop= "41DP" theandroid:text= "Start_camera_auto_addres"/> +  A</RelativeLayout>
1<?xml version= "1.0" encoding= "Utf-8"?>2<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"3      Package= "Com.example.camerademo"4Android:versioncode= "1"5Android:versionname= "1.0" >6 7<uses-SDK8Android:minsdkversion= "8"9Android:targetsdkversion= "/>"Ten<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> One  A<Application -Android:allowbackup= "true" -android:icon= "@drawable/ic_launcher" theAndroid:label= "@string/app_name" -Android:theme= "@style/apptheme" > -<Activity -Android:name= ". Mainactivity " +Android:label= "@string/app_name" > -<intent-filter> +<action android:name= "Android.intent.action.MAIN"/> A  at<category android:name= "Android.intent.category.LAUNCHER"/> -</intent-filter> -</activity> -</application> -  -</manifest>

  

Android System Photo source

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.