Hello,
I want to take a picture from the camera and set it as the background
of my view, my preview is contained into this view.
When I call the method takePicture(null, null, mPictureCallback), the
picture is displayed in the preview. However I would like to avoid the
display of this picture because I set it as the background of the view
just after the onPictureTaken() method of mPictureCallback. Here is
the code of the Preview method below.
How can I do that ?
------------------ Begin Preview.java --------------------->
class Preview extends SurfaceView implements SurfaceHolder.Callback
{
private SurfaceHolder mHolder;
private Camera mCamera;
private static final int IMAGE_WIDTH = 350;
private static final int IMAGE_HEIGHT = 270;
private PictureCallback mPicCallback = new Camera.PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
Bitmap myPic = BitmapFactory.decodeByteArray( data,
0,
data.length);
setBackgroundDrawable(new BitmapDrawable (myPic));
}
};
Preview(Context context)
{
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
mHolder.setFormat(PixelFormat.YCbCr_422_SP);
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder)
{
// The Surface has been created, acquire the camera and tell it
where
// to draw.
mCamera = Camera.open();
mCamera.setPreviewDisplay(holder);
}
public void surfaceDestroyed(SurfaceHolder holder)
{
// Surface will be destroyed when we return, so stop the
preview.
// Because the CameraDevice object is not a shared resource,
it's very
// important to release it when the activity is paused.
mCamera.stopPreview();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h)
{
// Now that the size is known, set up the camera parameters and
begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
}
---------------------- End Preview.java -------------------------->
Any help would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---