2017-04-18 28 views
0

你好,我想從設備獲取的圖像和網格視圖中顯示它時,我改變我對3拿給我的3五倍位置的圖像:我想補充的位圖圖像列表變爲網格視圖

BitmapFactory.decodeStream(new FileInputStream(file[i])); 

    private OpenDownloadedImages MyContext; 
    ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(); 

    public buttonAdapter(OpenDownloadedImages c){ 
     MyContext = c; 
    } 

    @Override 
    public int getCount() { 
     return file.length; 
    } 

    @Override 
    public Object getItem(int i) { 
     return file[i]; 
    } 

    @Override 
    public long getItemId(int i) { 
     return i; 
    } 

    @Override 
    public View getView(int i, View view, ViewGroup viewGroup) { 
     LayoutInflater inflater = getLayoutInflater(); 
     View vie = inflater.inflate(R.layout.row_list_fav,null); 
     ImageView imageView = (ImageView) vie.findViewById(R.id.imgFav); 
     imageView.setLayoutParams(new GridView.LayoutParams(180,250)); 
     imageView.setScaleType(ImageView.ScaleType.FIT_XY); 
     imageView.setPadding(0,0,0,0); 
     try { 
      File f=new File("sdcard/wallpaperHD"); 
      File file[] = f.listFiles(); 

      Bitmap b = BitmapFactory.decodeStream(new FileInputStream(file[i])); 
      //ImageView img=(ImageView)findViewById(R.id.dImage); 
      //img.setImageBitmap(b); 
      imageView.setImageBitmap(b); 

     } 
     catch (FileNotFoundException e) 
     { 
      e.printStackTrace(); 
     } 

     return imageView; 
    } 

    File f=new File("sdcard/wallpaperHD"); 
    File file[] = f.listFiles(); 
} 

謝謝!

+0

您可以附加屏幕截圖嗎?我很困惑你的意思是「它向我展示三次5次的圖像」 –

+0

應該如此。很好的噱頭。添加一個六點一來獲得更多樂趣!有什麼問題嗎? – greenapps

回答

0

我發現這裏的答案是代碼: 首先,我增加了新的功能:

公共靜態位圖decodeFile(文件F,INT寬度,詮釋HIGHT){

try { 
     //Decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(new FileInputStream(f),null,o); 

     //The new size we want to scale to 
     final int REQUIRED_WIDTH=WIDTH; 
     final int REQUIRED_HIGHT=HIGHT; 
     //Find the correct scale value. It should be the power of 2. 
     int scale=1; 
     while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT) 
      scale*=2; 

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

,並在獲取視圖使用此代碼更改 Bitmap b = BitmapFactory.decodeStream(new FileInputStream(file[i]));Bitmap bitmap = decodeFile(file[i],180,250); imageView.setImageBitmap(bitmap);