2012-03-18 74 views
1

所以這是我的問題。我有一個包含大位圖的圖像視圖(意味着由於位圖比圖像視圖大,圖像視圖只顯示它的一部分)。我希望能夠在座標x,y(x和y是位圖的座標)的imageview中居中位圖。在圖像視圖中移動位圖

任何想法如何實現它?

問候, 羅布

回答

0

嘗試

ImageView.ScaleType FIT_CENTER

看到這裏http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

現在取決於有多大,你可能要減少它正是你的位圖文件大小通過使用像這樣的東西

private Bitmap decodeFile(File f) { 
    Bitmap b = null; 
    try { 
     // Decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 

     FileInputStream fis = new FileInputStream(f); 
     BitmapFactory.decodeStream(fis, null, o); 
     fis.close(); 

     int scale = 1; 
     if (o.outHeight > 1024 || o.outWidth > 900) { 
      scale = (int) Math.pow(2, (int) Math.round(Math.log(1024/(double) Math.max(o.outHeight, o.outWidth))/Math.log(0.5))); 
     } 

     // Decode with inSampleSize 
     BitmapFactory.Options o2 = new BitmapFactory.Options(); 
     o2.inSampleSize = scale; 
     fis = new FileInputStream(f); 
     b = BitmapFactory.decodeStream(fis, null, o2); 
     fis.close(); 
    } catch (IOException e) { 
    } 
    return b; 
} 

積分How to scale bitmap to screen size?

+0

嗨,謝謝。但事情是,我不希望我的位圖調整到imageview的大小。我只是希望能夠將它移動到給定座標的圖像視圖的中心。 – rmonjo 2012-03-18 17:33:57