Jani Bela
Jani Bela

Reputation: 1670

Capturing image with camera and put an imageview on that, how?

is there any way to do this? I followed this tutorial (http://marakana.com/forums/android/examples/39.html) and it works great. In addition I put the FrameLayout (that contains the camera preview) into a RelativeLayout with an ImageView.

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >



    <FrameLayout
        android:id="@+id/preview"
        android:layout_width="330dp"
        android:layout_height="233dp"
        android:layout_marginTop="22dp"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" >
    </FrameLayout>

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image_on_preview" />

</RelativeLayout>

So now starting the application I have the camera and an imageview on that. If I save the picture to the SD card I get only the picture taken with the camera but the imageview does not appear (of course, why would appear). Now my question how can I save it as well? For better understanding I captured a screen shot when I use my application.

enter image description here

So I would like to save the both the camera preview and the imageview as well in one picture. I am not sure if it is possible, but the if I didnt have to save the pics onto the sd card it would be the best. I will add a button "save to SD card" later to save it.

**Update

Now I figured out a way. I save the picture on SD card then when the file created I change to another intent. It contains two imageviews, the "image_on_preview" and the other that has the source where I saved the picture before. Okay now I just have to somehow get tricky and combine the two imageviews :)

***Update2

Okay, I did it. In the second activity I convert both imageviews to bitmaps. Then I draw a Canvas and it puts them on each other, then I can save it directy to the SD card.

Upvotes: 3

Views: 1864

Answers (1)

Jani Bela
Jani Bela

Reputation: 1670

Since nobody answers and I solved the problem (and there is one vote up ) I show my own method.

  1. In the first activity, there is a RelativeLayout with a FrameLayout and an Imageview in it. Just like at the attached picture.
  2. I created a button, that capture the image. When I push that button, I save the captured photo into the SD card and change to activity2.
  3. In activity2 I read the saved image into a bitmap (I scale it instantly against OutOfMemory error), then add it to an imageview. Just like in activity1, I put the other imageview (cover) and the saved photo in a relative layout.
  4. For saving it to the SD card, I needed to create a canvas, and use canvas.drawBitmap(). I drew the captured photo first than the imageview (the cover), and place/scale them to look just like in the activity. The canvas will draw the bitmap and you can save it to the sd card. 5* (may be skipped) Delete the first picture.

Hope this will be useful to someone :)

Upvotes: 3

Related Questions