this.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath();对应路径
/storage/emulated/0/Android/data/com.example.testpplication/files/Pictures
public void getScreenWidthAndHeight(Context context){
this.heightPixels = context.getResources().getDisplayMetrics().heightPixels / 2 + 50;
this.widthPixels = context.getResources().getDisplayMetrics().widthPixels /3 - 10;
}
public Bitmap getimage(InputStream bitmapIS) {
BitmapFactory.Options newOpts = new BitmapFactory.Options();
newOpts.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeStream(bitmapIS,null, newOpts);
final int height = newOpts.outWidth;
final int width = newOpts.outHeight;
int inSampleSize = 1;
if (height > heightPixels || width > widthPixels) {
final int heightRatio = Math.round((float) height / (float) heightPixels);
final int widthRatio = Math.round((float) width / (float) widthPixels);
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
newOpts.inSampleSize = inSampleSize;// 设置缩放比例
newOpts.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeStream(bitmapIS,null, newOpts);
return bitmap;
}
public Bitmap getBitmap(Bitmap orightBitmap, float prevW, float prevH)
{
int mWidth=orightBitmap.getWidth();
int mHeight=orightBitmap.getHeight();
float scaleW=(float)prevW/mWidth;
float scaleH=(float)prevH/mHeight;
Matrix scaleMatrix = new Matrix();
scaleMatrix.postScale(scaleW, scaleH);
Bitmap resizeBmp = Bitmap.createBitmap(orightBitmap, 0, 0, mWidth,mHeight, scaleMatrix, true);
return resizeBmp;
}
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();
|