在发布之前,我真的在整个网络上搜索过.我的问题是我无法在不损失图像质量的情况下调整位图大小(质量非常差并且像素化).
我从相机获取位图然后我必须缩小它,所以我可以更快地将它上传到服务器.
这是进行采样的功能
public Bitmap resizeBitmap(Bitmap bitmap){
Canvas canvas = new Canvas();
Bitmap resizedBitmap = null;
if (bitmap !=null) {
int h = bitmap.getHeight();
int w = bitmap.getWidth();
int newWidth=0;
int newHeight=0;
if(h>w){
newWidth = 600;
newHeight = 800;
}
if(w>h){
newWidth = 800;
newHeight = 600;
}
float scaleWidth = ((float) newWidth) / w;
float scaleHeight = ((float) newHeight) / h;
Matrix matrix = new Matrix();
// resize the bit map
matrix.preScale(scaleWidth, scaleHeight);
resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, …Run Code Online (Sandbox Code Playgroud)