java - How to display image in another activity after taking a picture? -


i want photo have taken , shown in activity. preferably have button next activity, when clicked, displays image took. need simple way. i'm new android studio, therefore i'm not sure how solve this.

here's code

scanner.java

package mapp.com.sg.receiptscanner;  import android.content.intent; import android.graphics.bitmap; import android.os.bundle; import android.provider.mediastore; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.button; import android.widget.imageview;    public class scanner extends appcompatactivity {  imageview imageview; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_scanner);      button btncamera = (button)findviewbyid(r.id.btncamera);     imageview = (imageview)findviewbyid(r.id.imageview);      btncamera.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent intent = new intent(mediastore.action_image_capture);             startactivityforresult(intent,0);         }     }); }  protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     bitmap bitmap = (bitmap) data.getextras().get("data");     imageview.setimagebitmap(bitmap);   }  public void onclick(view view) {     intent = new intent(this, info.class);     startactivity(i); } } 

activity_scanner.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="16dp" android:paddingleft="16dp" android:paddingright="16dp" android:paddingtop="16dp" tools:context="mapp.com.sg.receiptscanner.scanner">  <imageview     android:layout_width="match_parent"     android:layout_height="fill_parent"     android:layout_weight="9"     android:id="@+id/imageview"     android:layout_alignparenttop="true"     android:layout_alignparentstart="true" />  <button     android:layout_width="150dp"     android:layout_height="wrap_content"     android:layout_weight="1"     android:background="#1f4991"     android:textcolor="@android:color/white"     android:text="open camera"     android:id="@+id/btncamera"     android:layout_marginbottom="14dp"     android:layout_above="@+id/proceedbtn"     android:layout_alignstart="@+id/proceedbtn" />  <button     android:id="@+id/proceedbtn"     android:layout_width="150dp"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:layout_centerhorizontal="true"     android:text="proceed"     android:background="#1f4991"     android:textcolor="@android:color/white"     android:onclick="onclick"/> 

try converting photo byte , send activity.

bytearrayoutputstream stream = new bytearrayoutputstream(); bitmap.compress(bitmap.compressformat.png, 90, stream); byte[] image = stream.tobytearray();  intent intent = new intent(this, youractivity.class); intent.putextra("photo", image); startactivity(intent); 

and in next activity , use decodebytearray create bitmap , set image view.

youractivity.class      byte[] bytearrayextra = getintent().getbytearrayextra("photo");      //bitmapoptions optional can create bitmap without also. description of use google developer docs.     //bitmapfactory.options: null-ok; options control downsampling , whether image should decoded, or size returned.      bitmap bitmap = bitmapfactory.decodebytearray(bytearrayextra, 0, bytearrayextra.length, new bitmapfactory.options());      //or     bitmap bitmap = bitmapfactory.decodebytearray(bytearrayextra, 0, bytearrayextra.length);       imageview.setimagebitmap(bitmap); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -