正文

图像合成(6)

Android多媒体开发高级编程 作者:(美)艾佛瑞


以下代码是一个辅助类,如同在第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);


上一章目录下一章

Copyright © 读书网 www.dushu.com 2005-2020, All Rights Reserved.
鄂ICP备15019699号 鄂公网安备 42010302001612号