[Android]修改bitmap大小

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;
    }

你可能感兴趣的:(Andorid)