2013-10-08 33 views

回答

1

應該使用==>BitmapFactory.decodeFile(pathName)方法。如果文件在外部stroge聲明許可清單中

+0

感謝鸚鵡,即工作。 – Nizzy

1

使用此方法BitmapFactory這將返回一個位圖對象..

BitmapFactory.decodeFile(path); 
0

其他的答案是正確的,但可能是你會得到一個OutOfMemoryErrorhigh resolution相似圖片相機圖片的圖像。所以要避免這一點,你可以使用下面的功能

public static Bitmap decodeFile(File f,int WIDTH,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; 
    } 

看到該錯誤https://stackoverflow.com/a/13226946/942224

相關問題