2012-01-04 9 views
1

これまでのところ、私のアプリはカメラを使ってAndroidCamera.javaの写真を撮ってから、画像を保存して新しいアクティビティPunch.javaで表示しています。この画面には2つのオプションがあります。画像を使用するか、画像を取り戻すにはボタンをクリックするとAndroidCamera.javaアクティビティに戻り、クリックするとアクティビティBeatEmUp.javaに移動します。これは新しいアクティビティです再度画像を表示する。Androidのカメラ画像を新しいアクティビティに移動

私はちょうど私がAndroidCamera.javaからPunch.javaに文字列を渡していますが、その下のコードを見ることができるこの新しい活動に再び画像を表示するBeatEmUp.java活動に置くために何を把握カントが、私が行うことができるとは思いませんこれは再びPunch.javaからBeatEmUp.javaまでですか?

更新アディルSoomro

BeatEmUp.javaUseボタンがクリックされたときに活動が今力が閉じます。

これは私はそれだけだろうと思っ正しいかどうか私はわからないとして、それは私がまた BeatEmUp.javaを追加したエラーを与えていた開始時の意図と同様に Use.putExtra("filepath",imagePath);intent.putExtra("filepath",imagePath); を変更しなければならなかった以下の更新された

OKコード私はPunch.java

に画像を表示するために使用するのと同じコードAndroidCamera.java

PictureCallback myPictureCallback_JPG = new PictureCallback(){ 

    public void onPictureTaken(byte[] arg0, Camera arg1) { 
     // TODO Auto-generated method stub 
     /*Bitmap bitmapPicture 
      = BitmapFactory.decodeByteArray(arg0, 0, arg0.length); */ 
     int imageNum = 0; 
     Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Punch"); 
     imagesFolder.mkdirs(); // <---- 
     String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; 
     File output = new File(imagesFolder, fileName); 
     while (output.exists()){ 
      imageNum++; 
      fileName = "image_" + String.valueOf(imageNum) + ".jpg"; 
      output = new File(imagesFolder, fileName); 
     } 

     Uri uriSavedImage = Uri.fromFile(output); 
     imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); 


     OutputStream imageFileOS; 
     try { 
      imageFileOS = getContentResolver().openOutputStream(uriSavedImage); 
      imageFileOS.write(arg0); 
      imageFileOS.flush(); 
      imageFileOS.close(); 

      Toast.makeText(AndroidCamera.this, 
        "Image saved", 
        Toast.LENGTH_LONG).show(); 

     } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     Intent intent = new Intent(getBaseContext(), Punch.class); 
     intent.putExtra("filepath",Uri.parse(output.getAbsolutePath()).toString()); 
     //just using a request code of zero 
     int request=0; 
     startActivityForResult(intent,request); 
    }}; 

Punch.java

String imagePath; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.punch); 

    imagePath = this.getIntent().getStringExtra("filepath"); 

    Button buse = (Button) findViewById(R.id.buse); 
    buse.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      Intent Use = new Intent(Punch.this, BeatEmUp.class); 
      Use.putExtra("filepath",imagePath); 
      startActivity(Use);     
     } 
    }); 

    Button bretake = (Button) findViewById(R.id.bretake); 
    bretake.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      Intent Retake = new Intent(Punch.this, AndroidCamera.class); 
      startActivity(Retake);    
     } 
    }); 

    String myRef = this.getIntent().getStringExtra("filepath"); 
    File imgFile = new File(myRef); 

    Log.e(">>>", myRef); 
    if(imgFile.exists()){ 

     Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
     ImageView myImage = (ImageView) findViewById(R.id.imagepunch); 
     myImage.setImageBitmap(myBitmap); 

    } 
} 

} 

BeatEmUp.java

String myRef = this.getIntent().getStringExtra("filepath"); 
    File imgFile = new File(myRef); 

    Log.e(">>>", myRef); 
    if(imgFile.exists()){ 

     Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 
     ImageView myImage = (ImageView) findViewById(R.id.imagepunch); 
     myImage.setImageBitmap(myBitmap); 

答えて

1

はい。あなたはその画像URIを次のActivityに再度送ることができます。

あなただけPunch.javaクラスで、クラスレベル変数に画像のパスを格納する必要がある、とBeatEmUp Activityを開始するとき、Intentに再びそのイメージパスを入れて、BeatEmUp

編集でそれを得る:

テイクPunch.java

String imagePath; 

と内部でクラスレベル

imagePath = this.getIntent().getStringExtra("filepath"); 

と私はクラスレベルの変数に格納し、それがString []画像=ファイルパス 'のようなものです再びそれを呼び出す方法BeatEmUp活動

Intent Use = new Intent(Punch.this, BeatEmUp.class); 
intent.putExtra("filepath",imagePath); 
startActivity(Use); 
+0

を開始。で、 '' Punch.java'しかし、私はそれをBeatEmUp.javaのインテントに入れる方法を理解していません – Matt

+0

私はあなたのために質問を更新しました。 – Matt

+0

Iveはあなたのためのペーストビンに入れますhttp://pastebin.com/utyAwrfE – Matt

関連する問題