最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年06月15日 15:10:29   作者:rainmj  
這篇文章主要為大家詳細介紹了Android利用Intent實現(xiàn)讀取圖片操作的相關資料,感興趣的小伙伴們可以參考一下

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

1、運行截圖

  

2、主要設計步驟

(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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

海口市| 平远县| 长寿区| 长丰县| 中卫市| 盘锦市| 桃江县| 弥勒县| 平定县| 广饶县| 罗山县| 漳浦县| 惠州市| 大冶市| 徐汇区| 河东区| 陇南市| 拉萨市| 安宁市| 高淳县| 安西县| 正安县| 治多县| 进贤县| 平乐县| 维西| 新和县| 鄂州市| 时尚| 米林县| 鱼台县| 磐石市| 百色市| 荃湾区| 安溪县| 房产| 五指山市| 洪湖市| 黄平县| 临海市| 白水县|