• android 加载本地图片与网络图片


    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myimage);
    ImageView image1
    = (ImageView) findViewById(R.myImage.image);
    //Bitmap bitmap = getLoacalBitmap("/aa/aa.jpg"); //从本地取图片
    Bitmap bitmap =
    getHttpBitmap(
    "http://blog.3gstdy.com/wp-content/themes/twentyten/images/headers/path.jpg");
    //从网上取图片
    image1 .setImageBitmap(bitmap); //设置Bitmap
    }

    /**
    * 加载本地图片
    *
    http://bbs.3gstdy.com
    *
    @param url
    *
    @return
    */
    public static Bitmap getLoacalBitmap(String url) {
    try {
    FileInputStream fis
    = new FileInputStream(url);
    return BitmapFactory.decodeStream(fis);
    }
    catch (FileNotFoundException e) {
    e.printStackTrace();
    return null;
    }
    }

    /**
    * 从服务器取图片
    *
    http://bbs.3gstdy.com
    *
    @param url
    *
    @return
    */
    public static Bitmap getHttpBitmap(String url) {
    URL myFileUrl
    = null;
    Bitmap bitmap
    = null;
    try {
    Log.d(TAG, url);
    myFileUrl
    = new URL(url);
    }
    catch (MalformedURLException e) {
    e.printStackTrace();
    }
    try {
    HttpURLConnection conn
    = (HttpURLConnection) myFileUrl.openConnection();
    conn.setConnectTimeout(
    0);
    conn.setDoInput(
    true);
    conn.connect();
    InputStream is
    = conn.getInputStream();
    bitmap
    = BitmapFactory.decodeStream(is);
    is.close();
    }
    catch (IOException e) {
    e.printStackTrace();
    }
    return bitmap;
    }
  • 相关阅读:
    mysql六:数据备份、pymysql模块
    mysql五:索引原理与慢查询优化
    mysql四:数据操作
    sql查询作业答案
    mysql四-2:多表查询
    mysql四-1:单表查询
    mysql五补充部分:SQL逻辑查询语句执行顺序
    mysql三-3:完整性约束
    mysql三:表操作
    mysql三-2:数据类型
  • 原文地址:https://www.cnblogs.com/xiao0/p/2170279.html
Copyright © 2020-2023  润新知