android 通过流获取bitmap

来源:互联网 发布:html5仿微信红包源码 编辑:程序博客网 时间:2024/04/25 20:26
private Bitmap decodeFile(File f){    Bitmap b = null;    try {        //Decode image size        BitmapFactory.Options o = new BitmapFactory.Options();        o.inJustDecodeBounds = true;        FileInputStream fis = new FileInputStream(f);        BitmapFactory.decodeStream(fis, null, o);        fis.close();        int scale = 1;        if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {            scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));        }        //Decode with inSampleSize        BitmapFactory.Options o2 = new BitmapFactory.Options();        o2.inSampleSize = scale;        fis = new FileInputStream(f);        b = BitmapFactory.decodeStream(fis, null, o2);        fis.close();    } catch (FileNotFoundException e) {    }    return b;}
++++++++++++++++++++++++++++++++++++++
InputStream is = getResources().openRawResource(R.drawable.icon);Bitmap mBitmap = BitmapFactory.decodeStream(is);Paint mPaint = new Paint();canvas.drawBitmap(mBitmap, 40, 40, mPaint);


0 0
原创粉丝点击