您的位置:首页 > 其它

ImageView多种显示图片的方式

2013-09-06 17:32 274 查看
自己总结的五种 方案

if (photos.size() > 0) {

   Photo photo = photos.get(0);

   String imagePath = ApplicationContext.getPoiImagePath();

   String path = photo.getPath();

   // 一种方法

   LogUtil.debug(path + "_____________________");

   Drawable img = BitmapDrawable

     .createFromPath(imagePath + "/" + path);

imgReview.setImageDrawable(img);

   // 二种方法

    Bitmap bitmap = BitmapFactory.decodeFile(imagePath + "/" +path);

imgReview.setImageDrawable(img);

   // 三种方案

    File file = new File(imagePath + "/" + path);

    Uri u = Uri.fromFile(file);

    imgReview.setImageURI(u);

   // 四种 方案

    Bitmap bit = BitmapFactory.decodeFile(imagePath + "/" + path); //

//    自定义//路径

    imgReview.setImageBitmap(bit);

   imgReview.setImageDrawable(img);

   // 第五种

    try {

    FileInputStream file1= new FileInputStream(imagePath + "/" +

    path);

          

    Bitmap bm = null;

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

    options.inSampleSize = 8;//图片的长宽都是原来的1/8

    BufferedInputStream bis = new BufferedInputStream(file1);

    bm = BitmapFactory.decodeStream(bis, null, options);

    imgReview.setImageBitmap(bm);

      

    } catch (FileNotFoundException e) {

    // TODO Auto-generated catch block

    LogUtil.error(e.getMessage(), e);

    }

  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: