zoukankan      html  css  js  c++  java
  • android 按比例获取SD卡缩略图

                     BitmapFactory.Options options = new BitmapFactory.Options();  
    options.inJustDecodeBounds = true;

    //获取这个图片的宽和高
    Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/darunfa/temp.jpg",options);//此时返回bm为空
    options.inJustDecodeBounds =false;
    //计算缩放比
    int be = (int)(options.outWidth / (float)600);
    if(be <= 0)
    be = 1;
    options.inSampleSize = be;
    //重新读入图片,注意这次要把options.inJustDecodeBounds设为false哦
    bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/darunfa/temp.jpg",options);
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    System.out.println(w+" "+h);
    imageView.setImageBitmap(bitmap);

    File file2= new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/darunfa/aaaa.jpg");
    try {
    FileOutputStream out = new FileOutputStream(file2);
    if(bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)){
    out.flush();
    out.close();
    }
    } catch (Exception e) {
    // TODO: handle exception
    }
  • 相关阅读:
    CentOS下设置ipmi
    CentOS 使用文件增加Swap空间
    CentOS LVM
    做IT需要掌握的电力基础知识
    CentOS 7搭建本地yum源
    Lsi卡和IB卡在CentOS中升级
    Mellanox 4036配置
    IdentityServer4入门二
    IdentityServer4入门一
    RAFT选举算法-分布式数据库困惑
  • 原文地址:https://www.cnblogs.com/fighter/p/2421370.html
Copyright © 2011-2022 走看看