N
NewPerson1
Neues Mitglied
- 0
Hallo,
ich habe eine Kamera-App gemacht.
Mein Problem: ich möchte das geschossene Bild auf eine andere Activity(Layout) anzeigen lassen. Leider weiß ich nicht, wie man das mit Bilder umsetzt (intent, putExtra, getExtra)!!!!!
Also es gibt eine MainActivity + main(Layout) & eine ZweiteActivity + zweite(Layout)
Das bedeutet, zuerst wird die main-layout angezeigt. Danach macht man ein Foto und dieses Bild soll dann auf zweite-layout angezeigt werden. Ich hoffe ihr könnt mich helfen.
//MainActivity
//Layout für MainActivity
//Layout für ZweiteActivity
ich habe eine Kamera-App gemacht.
Mein Problem: ich möchte das geschossene Bild auf eine andere Activity(Layout) anzeigen lassen. Leider weiß ich nicht, wie man das mit Bilder umsetzt (intent, putExtra, getExtra)!!!!!
Also es gibt eine MainActivity + main(Layout) & eine ZweiteActivity + zweite(Layout)
Das bedeutet, zuerst wird die main-layout angezeigt. Danach macht man ein Foto und dieses Bild soll dann auf zweite-layout angezeigt werden. Ich hoffe ihr könnt mich helfen.
//MainActivity
Code:
public class MainActivity extends Activity implements OnClickListener{
Button bSnap;
ImageView ivPic;
Intent iBild;
Bitmap bmp;
public static final int KamerCode = 15;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initialize();
InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
bmp = BitmapFactory.decodeStream(is);
}
private void initialize() {
ivPic = (ImageView) findViewById(R.id.ivPic);
bSnap = (Button) findViewById(R.id.bSnap);
bSnap.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.bSnap:
iBild = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//iBild = new Intent(MainActivity.this, ZweiteActivity.class);
//startActivityForResult(iBild, KamerCode);
startActivityForResult(iBild, KamerCode);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == KamerCode){
if (resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
ivPic.setImageBitmap(bmp);
}
}
}
}
//Layout für MainActivity
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
tools:context="com.picchat.paier.MainActivity" >
<ImageView
android:id="@+id/ivPic"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher"
android:layout_marginTop="250dp"
android:layout_marginLeft="70dp"/>
<Button
android:id="@+id/bSnap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Snap"
android:layout_marginLeft="20dp" />
<TextView
android:id="@+id/tvAppName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:text="PicChat"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
//Layout für ZweiteActivity
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
tools:context="com.picchat.paier.MainActivity" >
<ImageView
android:id="@+id/ivPic2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher"
android:layout_marginTop="250dp"
android:layout_marginLeft="70dp" />
<Button
android:id="@+id/bSnap"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Fertig"
android:layout_marginLeft="20dp" />
<TextView
android:id="@+id/tvAppName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:text="PicChat"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/bNeu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bSnap"
android:layout_centerHorizontal="true"
android:text="New"
android:layout_marginLeft="20dp" />
<EditText
android:id="@+id/etText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bNeu"
android:layout_alignParentLeft="true"
android:ems="10" />
</RelativeLayout>