首页 > 解决方案 > Android:如何使用 SonyCamera 远程 API 拍摄包围照片

问题描述

这个问题一直困扰着我直到 1 周。我想像包围一样拍照,但在Sony Camera API中它不支持。所以我编码它就像使用循环连续拍摄5张具有不同值(0,+2,-2,-4,+4)的图片。(使用按钮,当按下按钮时应该拍照5次)你可以看到下面的代码:
这个代码用于设置相机的快门速度

此拍照代码:

private void takePicture() {
    if (mLiveviewSurface == null || !mLiveviewSurface.isStarted()) {
        DisplayHelper.toast(getApplicationContext(), R.string.msg_error_take_picture);
        return;
    }
    new Thread() {
        @Override
        public void run() {
            try {
                JSONObject replyJson = mRemoteApi.actTakePicture();
                JSONArray resultsObj = replyJson.getJSONArray("result");
                JSONArray imageUrlsObj = resultsObj.getJSONArray(0);
                String postImageUrl = null;
                if (1 <= imageUrlsObj.length()) {
                    postImageUrl = imageUrlsObj.getString(0);                        continousShottingWithDifferentShutterValue();

                }
                if (postImageUrl == null) {
                    Log.w(TAG, "takePicture: post image URL is null.");
                    DisplayHelper.toast(getApplicationContext(), //
                            R.string.msg_error_take_picture);
                    return;
                }
                // Show progress indicator
                DisplayHelper.setProgressIndicator(SonyCameraActivity.this, false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}

这是for循环:

int val, posVal = 0;
int currentShutterSpeed = 0;

private void continousShottingWithDifferentShutterValue() {

    if (val == 0) {
        currentShutterSpeed = -5;
        setShutterSpeed(currentShutterSpeed);
        val++;
    } else if (val == 1) {
        currentShutterSpeed = 5;
        setShutterSpeed(currentShutterSpeed);
        val++;
    } else if (val == 2) {
        currentShutterSpeed = -10;
        setShutterSpeed(currentShutterSpeed);
        val++;
    } else if (val == 3) {
        currentShutterSpeed = 10;
        setShutterSpeed(currentShutterSpeed);
        val++;
    } else if (val == 4) {
        setShutterSpeedVal0(0);
        posVal++;
    }
    if (posVal == 3) {
        posVal = 0;
        val = 0;
    }
}

但是当我拍照时,有时 shutterSpeed 或 takePicture 会出错并且循环停止。

错误类型有:setShutterSpeed IOExeption 错误:500;或未设置 setShutterSpeed。有人使用 Sonycamera 远程 API,并且知道如何修复它或以不同的价值拍摄 5 次照片。将感谢任何想法。谢谢

标签: androidsony-camera-api

解决方案


我解决了这个问题。这是快门速度值错误。如您所知,在 Sony Camera Api 中没有快门速度的值,我将其写入相机设置中。并且 JSON 请求和响应不匹配,因此它显示错误 500。如果有人想使用快门速度值:这里是:

String shutterValue[] = {"30\"", "25\"", "20\"", "15\"", "13\"", "10\"", "8\"", "6\"",
        "5\"", "4\"", "3.2\"", "2.5\"", "2\"", "1.6\"", "1.3\"", "1\"", "0.8\"", "0.6\"", "0.5\"",
        "0.4\"", "1/3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30",
        "1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320", "1/400",
        "1/500", "1/640", "1/800", "1/1000", "1/1250", "1/1600", "1/2000", "1/2500", "1/3200", "1/4000"};

推荐阅读