//图片的裁剪
public Bitmap cutImage(String filePath){
BitmapFactory.Options opt = new BitmapFactory.Options();
//inJustDecodeBounds设置为true时,图像像素不被计入内存
opt.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(filePath, opt);
//获取bitmpa的宽高
int bmpWidth = opt.outWidth;
int bmpHeight = opt.outHeight;
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
//获取屏幕的宽高
int screenWidth = display.getWidth();
int screenHeigth = display.getHeight();
opt.inSampleSize = 1;
if (bmpWidth > bmpHeight) {
if (bmpWidth > screenWidth) {
opt.inSampleSize = bmpWidth/screenWidth;
}
}else {
if (bmpHeight > screenHeigth) {
opt.inSampleSize = bmpHeight/screenHeigth;
}
}
opt.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(filePath, opt);
return bitmap;
}
- 大概的思路就是这样,如果有写的不对的地方请指出,谢谢啦~~
图片裁剪
最新推荐文章于 2021-11-24 17:31:01 发布