2011-08-05 4 views
0

카메라에서 이미지를 캡처해야하는 앱이 있고 콘텐츠 리졸버를 사용하여 이미지를 미디어에 삽입했습니다. EXTERNAL_CONTENT_URI 그리고 getString() 이미지의 경로가 있고 다른 활동에서 번들로 전달했습니다.Android : 지정된 경로에서 이미지를 가져 오는 중 문제가 발생했습니다.

그 경로를 가져 와서 Bitmap에 넣으십시오. bitmap = BitmapFactory.decodeFile (filepath);

하지만 FILENOTFOUNDEXCEPTION 및 NULLPOINTEREXCEPTION이 표시됩니다. 해결 방법은 무엇입니까?

그래서 나는 첫 번째 활동에서 얻은 이미지를 먼저 파일로 설정 한 다음 그 파일을 쉽게 디코딩해야한다는 또 다른 접근법을 시도하고 있습니까?

제게 그 방법을 제안하십시오.

UPDATES ->

CODE: `//pass image path to other activity` 

case PICK_FROM_CAMERA : if (resultCode == RESULT_OK) 
      { 
       ContentValues values = new ContentValues(); 
       values.put(Images.Media.TITLE, "title"); 
       values.put(Images.Media.BUCKET_ID, "test"); 
       values.put(Images.Media.DESCRIPTION, "test Image taken"); 
       values.put(Images.Media.MIME_TYPE,"image/jpeg");  
       Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); 
       filepath = uri.getPath(); 
       Bitmap photo = (Bitmap) data.getExtras().get("data"); 
       //((ImageView)findViewById(R.id.selectedimage)).setImageBitmap(photo); 
       OutputStream outstream; 
       try 
       { 
        outstream = getContentResolver().openOutputStream(uri); 
        photo.compress(Bitmap.CompressFormat.JPEG,100,outstream); 
        outstream.close(); 
       } 
       catch (FileNotFoundException e) {} 
       catch (IOException e) {} 
       Intent intent = new Intent(this.getApplicationContext(),AnimationActivity.class); 
       Bundle bundle = new Bundle(); 
       bundle.putInt("flag", 0); 
       bundle.putString("filepath", filepath); 
       intent.putExtras(bundle); 
       startActivity(intent); 
      } 


Code: //show that image 

public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     ImageView img = (ImageView)findViewById(R.id.background);  
     Bitmap border = BitmapFactory.decodeResource(getResources(),R.drawable.border1); 
     Bundle extra = getIntent().getExtras(); 
     mfilepath = extra.getString("filepath"); 
     int flag = extra.getInt("flag"); 
     if(flag==1) 
     { 
      bgr= BitmapFactory.decodeFile(mfilepath); 
     } 
     if(flag==0) 
     { 
      bgr=BitmapFactory.decodeFile(mfilepath); 

      OutputStream outstream; 
      try 
      { 
       outstream = getContentResolver().openOutputStream(Uri.fromFile(new File(mfilepath))); 
       //bgr.compress(Bitmap.CompressFormat.JPEG,100,outstream); 
       outstream.close(); 
      } 
      catch (FileNotFoundException e) {} 
      catch (IOException e) {} 
     } 
     bmOverlay = Bitmap.createBitmap(border.getWidth(),border.getHeight(),bgr.getConfig()); 
     canvas = new Canvas(bmOverlay); 
     canvas.drawBitmap(bmOverlay, 0, 0, null); 
     canvas.drawBitmap(bgr, 0, 0, null); 
     canvas.drawBitmap(border,0,0, null); 
     canvas.save(); 
     img.setImageBitmap(bmOverlay); 
+2

이미지를 파일로 설정 하시겠습니까? 어떤 파일? 어떤 종류의 파일? –

+0

몇 가지 코드를 업로드 할 수 있습니까? 코드 없이는 말하기가 매우 어렵습니다. – Kgrover

+0

나는 엄마에게 질문을 취소 해 주셨습니다. – Geetanjali

답변

0

사용이 엄마 문제를 해결했다.

case PICK_FROM_CAMERA : if (resultCode == RESULT_OK) 
      { 
       ContentValues values = new ContentValues(); 
       values.put(Images.Media.TITLE, "title"); 
       values.put(Images.Media.BUCKET_ID, "test"); 
       values.put(Images.Media.DESCRIPTION, "test Image taken"); 
       values.put(Images.Media.MIME_TYPE,"image/jpeg");  
       Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); 
       filepath = uri.getPath(); 
       Bitmap photo = (Bitmap) data.getExtras().get("data"); 
       try 
       { 
        FileOutputStream outstream; =new FileOutputStream(filepath); 
        photo.compress(Bitmap.CompressFormat.JPEG,100,outstream); 
        outstream.close(); 
       } 
       catch (FileNotFoundException e) {} 
       catch (IOException e) {} 
       Intent intent = new Intent(this.getApplicationContext(),AnimationActivity.class); 
       Bundle bundle = new Bundle(); 
       bundle.putInt("flag", 0); 
       bundle.putString("filepath", filepath); 
       intent.putExtras(bundle); 
       startActivity(intent); 
      } 


Code: //show that image 

public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     ImageView img = (ImageView)findViewById(R.id.background);  
     Bitmap border = BitmapFactory.decodeResource(getResources(),R.drawable.border1); 
     Bundle extra = getIntent().getExtras(); 
     mfilepath = extra.getString("filepath"); 
     bgr= BitmapFactory.decodeFile(mfilepath); 
     bmOverlay = Bitmap.createBitmap(border.getWidth(),border.getHeight(),bgr.getConfig()); 
     canvas = new Canvas(bmOverlay); 
     canvas.drawBitmap(bmOverlay, 0, 0, null); 
     canvas.drawBitmap(bgr, 0, 0, null); 
     canvas.drawBitmap(border,0,0, null); 
     canvas.save(); 
     img.setImageBitmap(bmOverlay); 
1

이 간단한 방법을 시도, 나는 그것이 당신의 문제를 해결한다고 생각합니다.

private void savePicture(String filename, Bitmap b, Context ctx) { 
    try { 

     FileOutputStream out; 
     out = ctx.openFileOutput(filename, Context.MODE_WORLD_READABLE); 
     b.compress(Bitmap.CompressFormat.JPEG, 40, out); 
     if (b.compress(Bitmap.CompressFormat.JPEG, 40, out) == true) 

      out.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

편집 1 : 나는 당신이 물어 정확히 모르겠습니다 만, 나는이 방법을 찾는 것 같아요 : 대신의 OutputStream의 FileOutputStream에의

private void takePicture() { 
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
    File photo = new File(Environment.getExternalStorageDirectory(), 
      "Pic.jpg"); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); 
    imageUri = Uri.fromFile(photo); 
    startActivityForResult(intent, 0); 

} 
+0

검사 코드 없음 – Geetanjali

관련 문제