Android利用Intent實現(xiàn)讀取圖片操作
本文實例演示如何從圖庫(Gallery)中讀取圖像并用ImageView將它顯示出來,供大家參考,具體內(nèi)容如下
運行本示例前,需要先利用相機模擬拍攝一些圖片到圖庫中。
1、運行截圖
2、主要設(shè)計步驟
(1)添加ch1203_ReadGallery.axml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="30dp" android:layout_gravity="center" android:text="從圖庫中挑選一幅圖片" /> <TextView android:text="你挑選的圖片為:" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView1" android:layout_gravity="center" android:layout_margin="30dp" /> <ImageView android:id="@+id/myImageView" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
(2)添加ch1203ReadGallery.cs
using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Widget; namespace MyDemos.SrcDemos { [Activity(Label = "【例12-3】讀取圖庫圖片")] public class ch1203ReadGallery : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.ch1203_ReadGallery); var btn1 = FindViewById<Button>(Resource.Id.btn1); btn1.Click += delegate { var imageIntent = new Intent(); imageIntent.SetType("image/*"); imageIntent.SetAction(Intent.ActionGetContent); StartActivityForResult( Intent.CreateChooser(imageIntent, "選擇的圖片:"), 0); }; } protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok) { var imageView = FindViewById<ImageView>(Resource.Id.myImageView); imageView.SetImageURI(data.Data); } } } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android Intent傳遞對象的兩種方法(Serializable,Parcelable)詳細介紹
- Android基于Intent實現(xiàn)Activity之間數(shù)據(jù)傳遞的方法
- Android 通過Intent使用Bundle傳遞對象詳細介紹
- 在Android中通過Intent使用Bundle傳遞對象的使用方法
- Android中Intent傳遞對象的3種方式詳解
- 詳解Android中Intent傳遞對象給Activity的方法
- Android開發(fā)之利用Intent實現(xiàn)數(shù)據(jù)傳遞的方法
- android中intent傳遞list或者對象的方法
- Android系列之Intent傳遞對象的幾種實例方法
- Android 使用Intent傳遞數(shù)據(jù)的實現(xiàn)思路與代碼
- Android編程使用Intent傳遞圖片的方法詳解
相關(guān)文章
android ListView結(jié)合xutils3仿微信實現(xiàn)下拉加載更多
本篇文章主要介紹了android ListView結(jié)合xutils3仿微信實現(xiàn)下拉加載更多,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11android圖像繪制(七)ClipRect局部繪圖/切割原圖繪制總結(jié)
這幾天開始學(xué)游戲地圖制作,今天小小的總結(jié)一下Canvas的clipRect()接口的使用,接下來介紹ClipRect局部繪圖/切割原圖繪制感興趣的朋友可以了解下2013-01-01Android AutoWrapTextView中英文排版問題的解決方法
這篇文章主要給大家介紹了關(guān)于Android AutoWrapTextView中英文排版問題的解決方法,文中介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-05-05Android編程實現(xiàn)加載等待ProgressDialog的方法
這篇文章主要介紹了Android編程實現(xiàn)加載等待ProgressDialog的方法,實例分析了Android中加載等待類ProgressDialog的具體使用方法,需要的朋友可以參考下2015-12-12Android判斷當(dāng)前棧頂Activity的包名代碼示例
這篇文章主要介紹了Android判斷當(dāng)前棧頂Activity的包名代碼示例,分享了相關(guān)代碼,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下2018-02-02