android 图片指定大小并保存

图片保存至SD卡上,注意,只能缩小,不能将图片放大,最多只能到图片的原始大小

 

FileOutputStream outputStream = null;
            mBitmap = BitmapFactory.decodeFile(path, options);
            Log.e(TAG, "options.outHeight:" + options.outHeight + " :mScreenWidth:" + mScreenWidth);
            if (options.outHeight < mScreenWidth / 2) {
            	Log.e(TAG, "createBitMap invoke!");
                options.outHeight = mScreenWidth;
                options.outWidth = mScreenWidth;
                options.inJustDecodeBounds = false;
                mBitmap = BitmapFactory.decodeFile(path, options);
                outputStream = new FileOutputStream(file);
//保存图片
 if (mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)) {
                    outputStream.flush();
                    outputStream.close();
                }
//图片还是原始的大小,并没有放大
 Log.e(TAG, "bitmap width:" + mBitmap.getWidth() + " height:" + mBitmap.getHeight());
            }
 

 

你可能感兴趣的:(android)