Android利用Intent實(shí)現(xiàn)讀取圖片操作
本文實(shí)例演示如何從圖庫(Gallery)中讀取圖像并用ImageView將它顯示出來,供大家參考,具體內(nèi)容如下
運(yùn)行本示例前,需要先利用相機(jī)模擬拍攝一些圖片到圖庫中。
1、運(yùn)行截圖

2、主要設(shè)計(jì)步驟
(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android Intent傳遞對(duì)象的兩種方法(Serializable,Parcelable)詳細(xì)介紹
- Android基于Intent實(shí)現(xiàn)Activity之間數(shù)據(jù)傳遞的方法
- Android 通過Intent使用Bundle傳遞對(duì)象詳細(xì)介紹
- 在Android中通過Intent使用Bundle傳遞對(duì)象的使用方法
- Android中Intent傳遞對(duì)象的3種方式詳解
- 詳解Android中Intent傳遞對(duì)象給Activity的方法
- Android開發(fā)之利用Intent實(shí)現(xiàn)數(shù)據(jù)傳遞的方法
- android中intent傳遞list或者對(duì)象的方法
- Android系列之Intent傳遞對(duì)象的幾種實(shí)例方法
- Android 使用Intent傳遞數(shù)據(jù)的實(shí)現(xiàn)思路與代碼
- Android編程使用Intent傳遞圖片的方法詳解
相關(guān)文章
android ListView結(jié)合xutils3仿微信實(shí)現(xiàn)下拉加載更多
本篇文章主要介紹了android ListView結(jié)合xutils3仿微信實(shí)現(xiàn)下拉加載更多,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
android圖像繪制(七)ClipRect局部繪圖/切割原圖繪制總結(jié)
這幾天開始學(xué)游戲地圖制作,今天小小的總結(jié)一下Canvas的clipRect()接口的使用,接下來介紹ClipRect局部繪圖/切割原圖繪制感興趣的朋友可以了解下2013-01-01
Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程動(dòng)態(tài)按鈕實(shí)現(xiàn)方法,分享了onTouch方法及xml調(diào)用兩種實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-10-10
Android AutoWrapTextView中英文排版問題的解決方法
這篇文章主要給大家介紹了關(guān)于Android AutoWrapTextView中英文排版問題的解決方法,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-05-05
Android編程實(shí)現(xiàn)加載等待ProgressDialog的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)加載等待ProgressDialog的方法,實(shí)例分析了Android中加載等待類ProgressDialog的具體使用方法,需要的朋友可以參考下2015-12-12
Android判斷當(dāng)前棧頂Activity的包名代碼示例
這篇文章主要介紹了Android判斷當(dāng)前棧頂Activity的包名代碼示例,分享了相關(guān)代碼,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02
兩個(gè)surfaceView實(shí)現(xiàn)切換效果
這篇文章主要為大家詳細(xì)介紹了兩個(gè)surfaceView實(shí)現(xiàn)切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
Android中自定義對(duì)話框(Dialog)的實(shí)例代碼
這篇文章介紹了Android中自定義對(duì)話框(Dialog)的實(shí)例代碼,有需要的朋友可以參考一下2013-08-08

