14
我是一個Android的新手,所以我想知道是否有任何方法來獲取位圖的維度,而不會將位圖加載到內存中。獲取位圖的寬度和高度,而不加載到內存
我是一個Android的新手,所以我想知道是否有任何方法來獲取位圖的維度,而不會將位圖加載到內存中。獲取位圖的寬度和高度,而不加載到內存
您可以inJustDecodeBounds設置BitmapFactory.Options以獲取圖像的寬度和高度,而無需加載位圖像素在內存
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(inputStream, null, bitmapOptions);
int imageWidth = bitmapOptions.outWidth;
int imageHeight = bitmapOptions.outHeight;
inputStream.close();
有關詳細信息:
公共布爾inJustDecodeBounds
從以下版本開始:API級別1如果設置爲true,則 解碼器將返回null(無位圖),但out ...字段將仍然爲 設置,允許調用者查詢位圖而不用爲其像素分配內存。
不能正常工作,因爲該系統可以擴展關於屏幕密度的位圖,當你終於需要加載該位圖。 只有在BitmapFactory.Options.inScaled = false的情況下才會出現這種情況 – Tobliug 2015-08-04 18:13:41