Reporting back, as far as specifically capturing camera preview output to a 
bitmap and following the prior examples to draw, this is definitely 
possible.  There's some interesting things going on that may be helpful for 
others:

1. Camera preview size varies, some phones (such as the Samsung Galaxy S) 
support full-screen preview sizes.
2. Full screen preview sizes are not in the same aspect ratio as the camera 
image itself (on the galaxy s, it's 4:3, pretty standard for consumer 
digi-cams)
3. The full screen preview appears to be non-distorted, in that, it appears 
to be a slightly zoomed and cropped subset of the actual image buffer. 
 Taking a picture from the same preview reveals that more of the scene is 
captured.  This is important to note for those whom approximate knowledge of 
field of view is important.
4. Getting the main view which contains all views and simply drawing that to 
a bitmap does not work, because the camera surfaceview comes out blank.  So, 
we get a handle on the main containing view, which will indicate the final 
image size.  Get a handle on everything but the camera preview.  This might 
be a layout directly after the camera preview in a relativelayout which 
wraps everything else.  Create a bitmap from the camera view, downscale it 
(and possibly more as below), place it onto a bitmap the size of the 
containing view, then draw to that bitmap from the handle on everything but 
the camera preview.

Looks like there's 2 options as far as "screenshotting" a screen with a 
camera preview and other items on top (for example, an augmented reality 
scenario with simple non-openGL canvas drawing on top, some buttons etc)

a. Use Camera.takePicture() and Camera.PictureCallback.onPictureTaken(). 
 With the resulting image, scale it down, but to match the exact preview 
image, it must be zoomed and cropped accordingly, not sure if the crop 
position varies by device.  Copy the pixels into a bitmap the size of the 
containing view. 

b. Implement Camera.PreviewCallback and onPreviewFrame().  This seems the 
most raw method to use, and caution must be taken.  For 2.2+ (and 2.1 using 
reflection) it looks like there's some other ways to do this more 
efficiently - http://code.google.com/p/android/issues/detail?id=2794 

I may try option B and profile it to see if it's worth it.  Option A seems 
to work pretty well other than the scaling ickyness, and not knowing what's 
going to happen on other phones.

Don't know if this is any more helpful to anyone, it's basically integrating 
a few things from around, but this seems to work okay for Camera previews at 
least.


On Wednesday, June 8, 2011 2:11:19 PM UTC-4, Mark Murphy (a Commons Guy) 
wrote:
>
> On Wed, Jun 8, 2011 at 2:07 PM, Adam Ratana <[email protected]> wrote:
> > Mark Murphy, you said this is impossible, did you mean in the sense of 
> the
> > way DDMS grabs the full-monty screenshot?
>
> Um, for some definition of "full-monty", I presume, yes. :-)
>
> > I do hope that Android Handset/Tablet manufacturers catch on and 
> implement
> > hardware screen capturing options, a la iOS -- I don't believe 
> screenshots
> > are programmatically possible there either, for the same reasons, but the
> > user can capture one at any time with a combination of hardware buttons. 
>  It
> > will prevent us from having to come up with adhoc solutions like this, 
> and
> > allow the screenshot process to be user driven, and thus alleviating
> > security concerns.  I believe I read that either Samsung or Motorola may 
> do
> > this in future handsets?
>
> I haven't heard anything about that.
>
> -- 
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android 3.0 Programming Books: http://commonsware.com/books
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to