2013-02-28 25 views
4

顯示它後得到位圖的大小有一個imageview的我如何在ImageView的

<ImageView 
     android:id="@+id/imgCaptured" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:adjustViewBounds="true" 
     android:scaleType="fitXY" 
     android:src="@drawable/captured_image" /> 

我從相機捕獲圖像,轉換該圖像爲位圖。

Bitmap thumbnail; 
thumbnail = MediaStore.Images.Media.getBitmap(getActivity() 
        .getContentResolver(), imageUri); 

,當我在上面的ImageView顯示它之前獲得此位圖的分辨率一樣,

Log.i("ImageWidth = " + thumbnail.getWidth(), "ImageHeight = " 
       + thumbnail.getHeight()); 

其返回我在此之後ImageWidth = 2592 ImageHeight = 1936

我顯示此位圖在我上面的ImageView爲imgCaptured.setImageBitmap(thumbnail);然後我去我的imageview的大小爲

Log.i("ImageView Width = " + imgCaptured.getWidth(), 
       "ImageView Height = " + imgCaptured.getHeight()); 

這回我ImageView Width = 480 ImageView Height = 720

現在我的問題是,

  • 如何才能得到該位圖的大小後,我的ImageView顯示它。 我知道這可以通過使用此

    image.buildDrawingCache(); 
    Bitmap bmap = image.getDrawingCache(); 
    

    進行,但是這將創建大小相等的ImageView的新位圖。

  • 我也想知道,圖像在imageview中顯示後是否自動調整大小。如果是的話,有沒有什麼辦法可以在imageview中顯示圖片而不用調整圖片大小。

編輯

其實我已經捕獲的2592x1936的圖像。我在我的imageView中顯示了這個圖像,在這個圖像上做了一些其他操作。現在我想用相同的2592x1936分辨率保存此圖像。可能嗎?

在此先感謝。

+0

繪製要clarify-你的意思是在圖像視圖中位圖的大小寬度和高度?如果沒有填充,則兩者是等效的,ImageView的寬度/高度是位圖的寬度/高度。如果你有填充,就把它減掉。 – 2013-02-28 05:40:16

+0

是的,我的意思是在imageview中顯示它之後的位圖大小。 – 2013-02-28 05:42:58

+0

@Gabe Sechan其實我已經拍下了2592x1936的圖片。我在我的imageView中顯示了這個圖像,在這個圖像上做了一些其他操作。現在我想用相同的2592x1936分辨率保存此圖像。可能嗎? – 2013-02-28 05:47:36

回答

6

在ImageView中顯示位圖後,ImageView將創建一個BitmapDrawable對象以在ImageView的Canvas中繪製該對象。因此,您可以調用ImageView.getDrawable()方法來獲取BitmapDrawable的引用,並通過調用Drawable.getBounds(Rect rect)方法來獲取邊界。通過界限,你可以計算出位圖中的ImageView

Drawable drawable = ImageView.getDrawable(); 
//you should call after the bitmap drawn 
Rect bounds = drawable.getBounds(); 
int width = bounds.width(); 
int height = bounds.height(); 
int bitmapWidth = drawable.getIntrinsicWidth(); //this is the bitmap's width 
int bitmapHeight = drawable.getIntrinsicHeight(); //this is the bitmap's height 
+0

這個錯誤即將到來。 Drawable類型的方法getBounds()不適用於參數(Rect) – 2013-02-28 06:05:31

+0

嗯,我的錯誤 – 2013-02-28 06:07:53

+0

其工作坦克唐感謝很多 – 2013-02-28 06:14:35

相關問題