国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android利用Intent實(shí)現(xiàn)讀取圖片操作

2019-12-12 06:12:00
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

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="從圖庫(kù)中挑選一幅圖片" />  <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】讀取圖庫(kù)圖片")]  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);      }    }  }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 九龙城区| 荥经县| 报价| 四川省| 华坪县| 青州市| 社会| 东阿县| 顺平县| 长丰县| 张家界市| 拜城县| 台中县| 白山市| 蛟河市| 蓬莱市| 永定县| 洪泽县| 东乡族自治县| 红河县| 连云港市| 吴江市| 瓮安县| 寿宁县| 香格里拉县| 宣威市| 那坡县| 陈巴尔虎旗| 曲沃县| 临高县| 洪雅县| 安塞县| 福安市| 宁安市| 万安县| 南宫市| 平凉市| 水城县| 文成县| 海南省| 阜新|