Android 根据URI获取图片(从相册选择图片后返回)

来源:互联网 发布:手机照片制作视频软件 编辑:程序博客网 时间:2024/06/08 01:12
private Bitmap getBitmapFromUri(Uri uri) {        Bitmap bitmap = null;        try {            BitmapFactory.Options options = new BitmapFactory.Options();            int picWidth = options.outWidth;            int picHeight = options.outHeight;            WindowManager windowManager = getWindowManager();            Display display = windowManager.getDefaultDisplay();            int screenWidth = display.getWidth();            int screenHeight = display.getHeight();            options.inSampleSize = 1;            if (picWidth > picHeight) {                if (picWidth > screenWidth)                    options.inSampleSize = picWidth / screenWidth;            } else {                if (picHeight > screenHeight)                    options.inSampleSize = picHeight / screenHeight;            }            options.inJustDecodeBounds = false;            bitmap = BitmapFactory.decodeStream(getContentResolver()                    .openInputStream(uri), null, options);        } catch (Exception e) {            e.printStackTrace();            return null;        }        return bitmap;    }
0 0
原创粉丝点击