开发者

best way to transfer setparameters() on surfacechanged camera

I'm playing around with android camera functions. I'm trying to dynamically change the camera parameters using a menu onCheck and then calling the surfaceChanged to implement the changes.

public boolean onOptionsItemSelected(MenuItem item) {

            Camera.Parameters parameters = camera.getParameters();
            switch (item.getItemId()) {
            case R.id.EFFECT_AQUA:
                Toast.makeText(this, "AQUA", Toast.LENGTH_SHORT).show();
                if (item.isChecked()) item.setChecked(false);
                else item.setChecked(true);
                parameters.setColorEffect(Camera.Parameters.EFFECT_AQUA);
                surfaceChanged(null, 0, 0,0);
                return true;

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Camera.Parameters parameters = camera.getParameters();
        camera.setParameters(parameters);
        camera.startPreview();
        }

when I run the app, checking the menuItem calls the surfaceChanged but the chosen parameters are not used/set by the setpa开发者_如何学Pythonramater command.

I was thinking of implementing a global to capture the changes but I don't like it. Is there another way to transfer parameters when we do a surfaceChanged call?


From the given code snippet I'd say you forgot to publish the changed parameters to the camera. If you don't call setParameters(Parameters parameters) on your Camera instance, the camera will utilize the former parameter settings.

Camera.Parameters parameters = camera.getParameters(); parameters.setColorEffect(Camera.Parameters.EFFECT_AQUA); camera.setParameters(parameters); // add this line to your code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜