图像合成(6)

以下代码是一个辅助类,如同在第1章定义的那样,它用于通过URI加载一个位图对象,并将其缩放到不大于屏幕的大小。

 

     private Bitmap loadBitmap(Uri imageFileUri){

          Display currentDisplay = getWindowManager().getDefaultDisplay();

 

          float dw = currentDisplay.getWidth();

          float dh = currentDisplay.getHeight();

          // 期望是ARGB_4444

          Bitmap returnBmp = Bitmap.createBitmap((int)dw, (int)dh,

          Bitmap.Config.ARGB_4444);

 

          try {

               // 载入图像的尺寸而非图像本身

               BitmapFactory.Options bmpFactoryOptions =

               new BitmapFactory.Options();

               bmpFactoryOptions.inJustDecodeBounds = true;

               returnBmp = BitmapFactory.decodeStream(getContentResolver().

               openInputStream(imageFileUri), null, bmpFactoryOptions);

 

               int heightRatio = (int)Math.ceil(bmpFactoryOptions.

               outHeight/dh);

               int widthRatio = (int)Math.ceil(bmpFactoryOptions.

               outWidth/dw);

读书导航