これまでのところ、私のアプリはカメラを使ってAndroidCamera.java
の写真を撮ってから、画像を保存して新しいアクティビティPunch.java
で表示しています。この画面には2つのオプションがあります。画像を使用するか、画像を取り戻すにはボタンをクリックするとAndroidCamera.java
アクティビティに戻り、クリックするとアクティビティBeatEmUp.java
に移動します。これは新しいアクティビティです再度画像を表示する。Androidのカメラ画像を新しいアクティビティに移動
私はちょうど私がAndroidCamera.java
からPunch.java
に文字列を渡していますが、その下のコードを見ることができるこの新しい活動に再び画像を表示するBeatEmUp.java
活動に置くために何を把握カントが、私が行うことができるとは思いませんこれは再びPunch.java
からBeatEmUp.java
までですか?
更新アディルSoomro
BeatEmUp.java
Use
ボタンがクリックされたときに活動が今力が閉じます。
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);
を開始。で、 '' Punch.java'しかし、私はそれをBeatEmUp.javaのインテントに入れる方法を理解していません – Matt
私はあなたのために質問を更新しました。 – Matt
Iveはあなたのためのペーストビンに入れますhttp://pastebin.com/utyAwrfE – Matt