[Android]修改bitmap大小

来源:互联网 发布:图片来源于网络 编辑:程序博客网 时间:2024/05/21 19:37
public Bitmap getbitmap(Bitmap bitmap){        int width = bitmap.getWidth();        int height = bitmap.getHeight();        //放大為屏幕的1/2大小        float screenWidth  = getWindowManager().getDefaultDisplay().getWidth();// 屏幕宽(像素,如:480px)        float screenHeight = getWindowManager().getDefaultDisplay().getHeight();// 屏幕高(像素,如:800p)        Log.d("screen",screenWidth+"");        float scaleWidth = screenWidth/2/width;        float scaleHeight = screenWidth/2/width;        // 取得想要缩放的matrix參數        Matrix matrix = new Matrix();        matrix.postScale(scaleWidth, scaleHeight);        // 得到新的圖片        Bitmap newbm = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix,true);        return newbm;    }

0 0
原创粉丝点击