2015-03-02 78 views
1

在我的代碼圖像未打開在ImageView從SD卡我已經檢查'manifest.xml'中的權限。 同樣,如果我嘗試打開它使用靜態名稱,那麼它會顯示ImageView,但不是動態的。圖像不顯示在ImageView動態從SD卡

主要活動

private OnClickListener OnCapture = new OnClickListener() {   
    @Override 
    public void onClick(View v) { 
     String time = mCamUtils.clickPicture(); 
     nextActivity = new Intent(MainActivity.this,EffectActivity.class); 
     nextActivity.putExtra("ImageName", time); 
     startActivity(nextActivity); 
     finish(); 
    } 
}; 

EffectActivity

public class EffectActivity extends Activity { 

Intent getActivity = null; 
ImageView image = null; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.effectactivity); 

    getActivity = getIntent(); 
    String name = getActivity.getStringExtra("ImageName"); 

    String path = Environment.getExternalStorageDirectory()+"/GalaxyPhoto/GX_" +name+ ".JPG"; 

    Toast.makeText(getApplicationContext(), path, Toast.LENGTH_LONG).show(); 
    image = (ImageView) findViewById(R.id.imageView1); 
    File f = new File(path); 
    byte[] b = new byte[(int)f.length()]; 
    if(f.exists()) 
    { 
     try 
     { 
      if(f.exists()) 
      { 
       FileInputStream ff = new FileInputStream(f); 
       ff.read(b); 
       Bitmap g = BitmapFactory.decodeFile(path); 
       image.setImageBitmap(g); 
       ff.close(); 
      } 
      else 
      { 
       Toast.makeText(getApplicationContext(), "ELSE", Toast.LENGTH_LONG).show(); 
      } 
     } 
     catch(Exception e) 
     { 

     } 
    } 
} 

}

我試圖打開圖像,我這個活動之前保存在和我趕上圖像的名稱在這裏,但沒有顯示圖像。

+0

顯示代碼保存在SD卡上的圖像,並開始'EffectActivity'活動 – 2015-03-02 05:58:42

+0

其長期和落後它6班工作和圖像保存在文件夾中我檢查它的名字也打印它的TOAST,但仍然圖像不打開ImageView – 2015-03-02 06:00:25

+0

你加載圖像時出現異常? – Fahim 2015-03-02 06:02:07

回答

0
String path = Environment.getExternalStorageDirectory()+"/GalaxyPhoto/GX_" +name+ ".JPG"; 

在這一行嘗試改變「JPG」到「JPG」。我想你的文件擴展名可能是小寫字母,它可能會說f.exists假的。 希望它會有所幫助。

+0

不工作謝謝你的回覆我尊重你.. – 2015-03-02 06:10:55

+0

在catch塊中放一行e.printStackTrace並顯示你的堆棧跟蹤。 – 2015-03-02 06:13:05

+0

也顯示你的方法代碼mCamUtils.clickPicture() – 2015-03-02 06:15:00

0
String fname = "Pic-" + System.currentTimeMillis() + ".png"; 
File image= new File(imagesFolder, fname); 
Bitmap bitmap; 

      BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); 

      picturePath=image.getAbsolutePath(); 

      bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bitmapOptions); 

      imageView.setImageBitmap(bitmap); 

試試這個代碼

+0

對不起尊重你先生的答覆,但不工作.. – 2015-03-02 06:16:41