2017-02-11 47 views
1

獲取參數的方法我有方法來調整圖像,我想從陣列參數,但它一直顯示錯誤說如何從陣列

incompatible types 
found int 
required android.graphics.drawable.Drawable 

這是我的方法

public Drawable ResizeImage (int imgResize){ 
     Display imgPost = getWindowManager().getDefaultDisplay(); 
     double dvcWidth = imgPost.getWidth(); 

     BitmapDrawable imgBD = (BitmapDrawable)this.getResources().getDrawable(imgResize); 
     double imgHeight = imgBD.getBitmap().getHeight(); 
     double imgWidth = imgBD.getBitmap().getWidth(); 

     double imgRatio = dvcWidth/imgWidth; 
     int newImgHeight = (int) (imgHeight*imgRatio); 

     Bitmap imgBmap = BitmapFactory.decodeResource(getResources(),imgResize); 
     Drawable imgDrawable = new BitmapDrawable(this.getResources(),getResizedBitmap(imgBmap,newImgHeight,(int) dvcWidth)); 

     return imgDrawable; 
    } 

我的數組

int[] imgDvc= new int[]{ 
      ResizeImage(R.drawable.pc), 
      R.drawable.ps4, 
      R.drawable.xbone 
} 

,我打電話給我的陣列通過這裏

List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); 
     for(int i=0;i<10;i++){ 
     HashMap<String, String> hm = new HashMap<String,String>(); 
     hm.put("Dvc", Integer.toString(imgDvc[i])); 
     aList.add(hm); 
    } 
String[] game= {"Dvc"}; 

我用它來填充listview,謝謝你的回答。

+0

代碼中的哪行代表錯誤指的是? –

+0

@MehmetKologlu this ResizeImage(R.drawable.pc)line。 – sh4man

+1

哦,我現在看到它。你已經聲明瞭一個int數組,但你試圖在其中添加一個'Drawable'。你不能這樣做。 –

回答

0

如果您打算放3張圖片,只需使用3張圖片並調整大小即可調整大小

+0

我無法做到這一點從imageview,圖像大約800x600,它會減慢設備。我想通過java調整它的大小。 – sh4man

+0

將位圖加載到內存中並不是一種快速方法。 (這正是decodeBitmap所做的)我非常有信心使用imageView的XML屬性scaleX和scaleY會更快 –

+0

800x600甚至不是一個大圖像。 –