• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Camera Preview

I have a camera activity in my app. Once I get the byte array back from onPicturetaken, I convert the byte array to a bitmap using bitmap factory. How do I take that bitmap and pass it to a previewer so the user can see the picture they took.

Something like this:

ImageActivity.java
Code:
public class ImageActivity extends Activity
{
    //extraneous details omitted...
    //...

    byte[] picData;
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
         super.onCreate(savedInstanceState);
    
         byte[] picBytes = getIntent().getByteArrayExtra("picBytes");
         
         Bitmap bm = BitmapFactory.decodeByteArray(picBytes, 0, picBytes.length);

         setContentView(R.layout.main);

         ImageView image = (ImageView)findViewById(R.id.Image);
         image.setImageBitmap(bm);
         image.invalidate();
    }

main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/Layout"
      android:orientation="vertical" 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
<ImageView
      android:id="@+id/Image"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />
</LinearLayout>

CameraActivity.java
Code:
public class CameraActivity extends Activity implements Camera.PictureCallback
{
       //Extraneous details omitted...
       //...

       public void onPictureTaken(byte[] data, Camera cam)
       {
             Intent intent = new Intent(CameraActivity.this, ImageActivity.class);
             intent.putExtra("picBytes", data);
             startActivity(intent);
             finish(); //Leave out to allow user to go back to camera
       }
 
       //.....
}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones