I'm trying to allow a user to take a picture with a camera, and then 'draw' over this image using the finger paint application in the API Demos. This works OK on the emulator, but on the phone the fingerpaint intent never shows up; is it simply too slow/intensive, or am I doing something wrong? Why does it stay black when I try to run the fingerpaint app?
The steps are as follows:
1. Create Camera Stuff, and do camera.takePicture(blah), and onCallbackJpeg (byte[] data ...) {//store data}
2. A Button in Options menu starts a new activity (the fingerpaint application), but I do Intent.putextras, and put in the byte array so the fingerpaint application has access to the bitmap data
3. In fingerpaint, do getIntent().getExtras() and recover the byte array. Then, convert the byte array to a mutable bitmap and set that bitmap as the background canvas
Anyone have any ideas how to speed this up so it works on hardware?
Camera Code is posted Below:
Using java Syntax Highlighting
- package com.android.CamTest;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import android.hardware.Camera;
- import android.hardware.Camera.PictureCallback;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.SurfaceHolder;
- import android.view.SurfaceView;
- import android.view.Window;
- // ----------------------------------------------------------------------
- public class CamTest extends Activity {
- private Preview mPreview;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Hide the window title.
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- // Create our Preview view and set it as the content of our activity.
- mPreview = new Preview(this);
- setContentView(mPreview);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- menu.add(0, 1, 0, "take picture");
- menu.add(0, 2, 0, "view picture");
- return true;
- }
- @Override
- public boolean onMenuItemSelected(int featureId, MenuItem item) {
- switch(item.getItemId()) {
- case 1:
- try {
- mPreview.captureImage();
- } catch (Exception e) {
- e.printStackTrace();
- }
- break;
- case 2:
- Intent i = new Intent(this, FingerPaint.class);
- if(mPreview.picdata != null)
- i.putExtra("picdata", mPreview.picdata);
- // mPreview.mCamera.release();
- // setContentView(R.layout.main);
- startActivity(i);
- break;
- }
- return true;
- }
- }
- // ----------------------------------------------------------------------
- class Preview extends SurfaceView implements SurfaceHolder.Callback {
- SurfaceHolder mHolder;
- public Camera mCamera;
- public Bitmap bm;
- public byte[] picdata;
- Preview(Context context) {
- super(context);
- // Install a SurfaceHolder.Callback so we get notified when the
- // underlying surface is created and destroyed.
- mHolder = getHolder();
- 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();
- }
- public void captureImage() {
- Camera.Parameters params = mCamera.getParameters();
- mCamera.setParameters(params);
- Camera.PictureCallback cb = new PictureCallback() {
- public void onPictureTaken(byte[] data, Camera camera) {
- picdata = data;
- // bm = BitmapFactory.decodeByteArray(data, 0, data.length);
- try {
- // FileOutputStream out = new FileOutputStream("/sdcard/mypick.png");
- // myimage.compress(Bitmap.CompressFormat.PNG, 10, out);
- // out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- // ImageView mImageDisplay = (ImageView) findViewById(R.id.image_display);
- // mImageDisplay.setImageBitmap(b);
- }
- };
- mCamera.takePicture(null, null, cb);
- mCamera.stopPreview();
- // mCamera.release();
- }
- }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4

