如何在Android中调整图像大小?我正在创建一个应用程序,并希望设置一个图库视图。我不希望画廊视图中的图像是完全大小的。如何在Android中调整图像大小?
3 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
Bitmap yourBitmap;Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);
resized = Bitmap.createScaledBitmap(yourBitmap,(int)(yourBitmap.getWidth()*0.8), (int)(yourBitmap.getHeight()*0.8), true);
慕无忌1623718
TA贡献1744条经验 获得超4个赞
public Bitmap resizeBitmap(String photoPath, int targetW, int targetH) { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(photoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; int scaleFactor = 1; if ((targetW > 0) || (targetH > 0)) { scaleFactor = Math.min(photoW/targetW, photoH/targetH); } bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; //Deprecated API 21 return BitmapFactory.decodeFile(photoPath, bmOptions); }
- 3 回答
- 0 关注
- 389 浏览
添加回答
举报
0/150
提交
取消