1

我正在尝试制作一个用户可以拍照的屏幕。这张照片将进入数据库。问题是,我尝试了多种方法,并且在每种方法中,我都需要使用 PictureCallback。但是无论如何,从不调用 PictureCallback 的 onPictureMethod。

我已经尝试过查看thisthis,但仍然无法移动。

编辑:使用 Android 2.2 (API 8)

编辑代码:

package touchcare.idealogix.android;

//imports

public class CameraActivityTest extends Activity implements SurfaceHolder.Callback
{
private SurfaceView surfaceCamera;
private SurfaceHolder holderCamera;
private Camera camera;
private Button btnCapture;
private PictureCallback mPictureJpg;
private PictureCallback mPictureRaw;
private ShutterCallback shutterCallback;

@Override public void onCreate(Bundle bundle){
    super.onCreate(bundle);
    setContentView(R.layout.layout_camera);

    Log.d("PICTURE", "ACTIVITY START");

    surfaceCamera = (SurfaceView) findViewById(R.id.surfaceCamera);
    btnCapture = (Button) findViewById(R.id.btnCapture);
    holderCamera =  surfaceCamera.getHolder();

    holderCamera.addCallback(this);
    holderCamera.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    shutterCallback = new ShutterCallback() 
    {   
        @Override
        public void onShutter() 
        {
            //DONOTHING
        }
    };

    mPictureRaw = new PictureCallback() 
    {   
        @Override
        public void onPictureTaken(byte[] data, Camera camera)
        {
            //DONOTHING
        }
    };

    mPictureJpg = new PictureCallback()
    {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) 
        {
            Log.d("PICTURE", "ON PICTURE TAKEN START");

            Intent intent = getIntent();

            final boolean beds = intent.getExtras().getBoolean(Main.BEDS, false);
            final boolean nurse = intent.getExtras().getBoolean(Main.NURSE, false);
            final int position = intent.getExtras().getInt(Main.POSITION, 0);

            if(beds)
            {
                BedroomDataSource bedDs = new BedroomDataSource(CameraActivityTest.this);
                String where = SQLiteBedroomHelper.COLUMN_UID + "=" + AppData.getBedrooms().get(position).getUid();
                bedDs.open();
                bedDs.updateBedroom(where, null, null, null, null, null, null, data);
                bedDs.close();
                Log.d("PICTURE", "BEDS BOOLEAN");
                AppData.getBedrooms().get(position).setImage(data);
            }else if(nurse)
            {

            }

            Log.d("PICTURE", "ON PICTURE TAKEN END");

            finish();
        }
    };

    btnCapture.setOnClickListener(new View.OnClickListener() 
    {   
        @Override
        public void onClick(View arg0) 
        {               
            camera.takePicture(shutterCallback, mPictureRaw, mPictureJpg);
        }
    });
}

@Override public void surfaceCreated(SurfaceHolder holder)
{
    camera = Camera.open();

    Camera.Parameters params = camera.getParameters();      

    params.setPreviewSize(holder.getSurfaceFrame().width(), holder.getSurfaceFrame().height());
    params.setPictureSize(32, 32);
    params.setJpegQuality(100);

    camera.setParameters(params);

    try
    {
        camera.setPreviewDisplay(holder);
    }catch(IOException ex){
        Log.d("PICTURE", "PREVIEW EXCEPTION");
    }

    camera.startPreview();

    Log.d("PICTURE", "SURFACE CREATED");
}

@Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
{
    Log.d("PICTURE", "SURFACE CHANGED");
}

@Override public void surfaceDestroyed(SurfaceHolder holder)
{
    camera.stopPreview();

    camera.release();

    Log.d("PICTURE", "SURFACE DESTROYED");
}
}

谢谢。

编辑:看起来拍摄了一些照片并达到了回调。数据库获取照片,并在位图中加载回来就好了。但根据我拍摄的照片,回调没有到达。更小更简单的事情有 100% 的机会执行回调。

4

1 回答 1

-1

看起来您创建了回调 mPicture,然后从不将其设置为任何内容的回调。我从来没有使用过任何图片的东西,所以我不能建议在哪里设置它,但据我所知,你需要注册回调才能调用它,只是定义它对你没有任何好处。

于 2012-04-24T15:00:15.537 回答