android - Show captured image in new activity -
i new in android , building small app take picture camera , save gallery.
here function capture image.
private void oncaptureimageresult(intent data) { bitmap thumbnail = (bitmap) data.getextras().get("data"); bytearrayoutputstream bytes = new bytearrayoutputstream(); thumbnail.compress(bitmap.compressformat.jpeg, 90, bytes); file destination = new file(environment.getexternalstoragedirectory(), system.currenttimemillis() + ".jpg"); fileoutputstream fo; try { destination.createnewfile(); fo = new fileoutputstream(destination); fo.write(bytes.tobytearray()); fo.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } }
this activity_main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="5dp" > <button android:id="@+id/btnselectphoto" android:background="#149f82" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="select photo" /> </linearlayout> </linearlayout>
what want when image captured want display image on activity(page) not on same activity have button capture image.how that.
thanks in advance
you have pass path new activity method.
intent intent = new intent(this, newactivity.class); intent.putextra("myimagepath", destination.getabsolutefile()); startactivity(intent);
and in new activity
file imgfile = new file(filepath); if(imgfile.exists()){ bitmap mybitmap = bitmapfactory.decodefile(imgfile.getabsolutepath()); imageview myimage = (imageview) findviewbyid(r.id.imageviewtest); myimage.setimagebitmap(mybitmap); }
Comments
Post a Comment