zoukankan      html  css  js  c++  java
  • mono for android 读取网络远程图片

    布局

    <?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/btn"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="查看" />
      <ImageButton
      android:id="@+id/imageView"
      android:layout_width="fill_parent"
      android:layout_height="200px" />
    </LinearLayout>


    C#代码

            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
    
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);
    
                Button btn = FindViewById<Button>(Resource.Id.btn);
               
                btn.Click += new EventHandler(btn_Click);
                
                
            }
    
            void btn_Click(object sender, EventArgs e)
            {
                ImageView imgview = FindViewById<ImageView>(Resource.Id.imageView);
                imgview.SetImageBitmap(getImage("http://hiphotos.baidu.com/baidu/pic/item/7d8aebfebf3f9e125c6008d8.jpg"));
            }
    
            public static Bitmap getImage(string imagepath) {
                
                URL url=null;
                Bitmap bitmap = null;
                try
                {
                    url = new URL(imagepath);
                }
                catch (Exception e)
                {
    
                } 
    
                HttpURLConnection conn = (HttpURLConnection)url.OpenConnection();
                conn.DoInput = true;
                conn.Connect();
                System.IO.Stream str = conn.InputStream;
                bitmap = BitmapFactory.DecodeStream(str);
                str.Close();
    
                return bitmap;
            }
  • 相关阅读:
    搭建mongoDB 配置副本集 replSet
    关于erlang解析json数据
    互联网精准广告定向技术
    cmd 查看端口占用情况
    nutzboot dubbo zookeeper简单使用
    一些常用名词
    小程序video置顶
    html 5 video audio
    android webview 视频相关
    微信小程序
  • 原文地址:https://www.cnblogs.com/zhahainie/p/3552209.html
Copyright © 2011-2022 走看看