当前位置: 代码迷 >> Android >> android 图片指定大小并封存
  详细解决方案

android 图片指定大小并封存

热度:36   发布时间:2016-05-01 12:39:43.0
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());            }
?

?

  相关解决方案