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

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

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

2019-10-23 20:36:34
字體:
供稿:網(wǎng)友

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

1、運(yùn)行截圖

   Android,Intent讀取圖片

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í)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东宁县| 化州市| 凤冈县| 扶绥县| 盐城市| 乌鲁木齐县| 临猗县| 大埔县| 绵竹市| 同德县| 八宿县| 河池市| 东源县| 安远县| 浙江省| 绥中县| 六枝特区| 宁陕县| 瑞昌市| 汉中市| 文登市| 卓资县| 甘肃省| 石柱| 喀喇| 柳林县| 中牟县| 东源县| 德令哈市| 通化市| 尚义县| 治多县| 贵溪市| 油尖旺区| 楚雄市| 本溪市| 浦东新区| 红河县| 揭西县| 临城县| 航空|