Android 中Bitmap对象如何使用decodeStream生成缩略图?  
   在网上看了好多都是用decodeFile这种方式生成的。   谁可以告知一下?

解决方案 »

  1.   

    decodeFile没有从网络解码图片的能力 
      

  2.   

    BitmapFactory.Options options = new BitmapFactory.Options();
         //options.inSampleSize = 3;
         options.outHeight = 200;
         options.inJustDecodeBounds = true;
         //options.
         if (position < 0) {      position = position + mImageDirs.size();     }
         // 获取这个图片的宽和高
         Bitmap bm = BitmapFactory.decodeFile(this.mImageDirs
           .get(position % mImageDirs.size()), options); //此时返回bm为空
         options.inJustDecodeBounds = false;
         int be = options.outHeight / 20;
         if(be%10 !=0)
          be+=10;
         be=be/10;
         if (be <= 0)
          be = 1;
         options.inSampleSize = be;
         bm = BitmapFactory.decodeFile(this.mImageDirs.get(position
           % mImageDirs.size()), options);这里使用decodeFile生成的缩略图,我希望用decodeStream的方式来生成缩略图
      

  3.   


    public static Bitmap getBitmapByUrl(HttpGet httpGet,String strurl, int displayWidth,
    int displayHeight) throws IOException, URISyntaxException {
    URL url = new URL(strurl);
    getHttpClient();

    httpGet.setURI(new URI(strurl));

    HttpResponse response = httpClient.execute(httpGet);
    InputStream ins=null;
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    ins=response.getEntity().getContent();
    }
    else
    return null;
    //url.openConnection().setDefaultUseCaches(true);
    Options options = new Options();
    options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeStream(ins, null, options);
    int srcWidth = options.outWidth;
    ins.close();
    ins = null;
    options.inJustDecodeBounds = false;
    Log.d("Tag", "with:" + options.outWidth);
    // int be = (int) (((double) options.outWidth) / ((double)
    // displayWidth));
    int be = 0;
    be = (int) Math.round(((((double) srcWidth) / ((double) displayWidth)))); options = new Options();
    options.inSampleSize = be;
    //ins = url.openStream();

    response = httpClient.execute(httpGet);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    ins=response.getEntity().getContent();
    } bitmap = BitmapFactory.decodeStream(ins, null, options);

    ins.close();
    return bitmap;

    }