【问题标题】:integrate photo editing AVIORY API with camera app将照片编辑 AVIORY API 与相机应用程序集成
【发布时间】:2016-02-09 14:41:12
【问题描述】:

我想将第 3 方照片编辑 AVIORY api 与我正在开发的本机相机应用程序集成,但我无法做到。该 api 在拍摄照片后工作。请让我知道如何实现这个 AVIORY API。这是api的链接:https://developers.aviary.com

 enter code here
 void takePicturePressed() {
    if( MyDebug.LOG )
        Log.d(TAG, "takePicturePressed");
    if( camera == null ) {
        if( MyDebug.LOG )
            Log.d(TAG, "camera not opened!");
        /*is_taking_photo_on_timer = false;
        is_taking_photo = false;*/
        this.phase = PHASE_NORMAL;
        return;
    }
    if( !this.has_surface ) {
        if( MyDebug.LOG )
            Log.d(TAG, "preview surface not yet available");
        /*is_taking_photo_on_timer = false;
        is_taking_photo = false;*/
        this.phase = PHASE_NORMAL;
        return;
    }
    //if( is_taking_photo_on_timer ) {
    if( this.isOnTimer() ) {
        takePictureTimerTask.cancel();
        takePictureTimerTask = null;
        if( beepTimerTask != null ) {
            beepTimerTask.cancel();
            beepTimerTask = null;
        }
        /*is_taking_photo_on_timer = false;
        is_taking_photo = false;*/
        this.phase = PHASE_NORMAL;
        if( MyDebug.LOG )
            Log.d(TAG, "cancelled camera timer");
        showToast(take_photo_toast, R.string.cancelled_timer);
        return;
    }
    //if( is_taking_photo ) {
    if( this.phase == PHASE_TAKING_PHOTO ) {
        if( is_video ) {
            if( !video_start_time_set || System.currentTimeMillis() - video_start_time < 500 ) {
                // if user presses to stop too quickly, we ignore
                // firstly to reduce risk of corrupt video files when stopping too quickly (see RuntimeException we have to catch in stopVideo),
                // secondly, to reduce a backlog of events which slows things down, if user presses start/stop repeatedly too quickly
                if( MyDebug.LOG )
                    Log.d(TAG, "ignore pressing stop video too quickly after start");
            }
            else {
                stopVideo(false);
            }
        }
        else {
            if( MyDebug.LOG )
                Log.d(TAG, "already taking a photo");
        }
        return;
    }

    // make sure that preview running (also needed to hide trash/share icons)
    this.startCameraPreview();

    //is_taking_photo = true;
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getContext());
    String timer_value = sharedPreferences.getString("preference_timer", "0");
    long timer_delay = 0;
    try {
        timer_delay = Integer.parseInt(timer_value) * 1000;
    }
    catch(NumberFormatException e) {
        if( MyDebug.LOG )
            Log.e(TAG, "failed to parse preference_timer value: " +    timer_value);
        e.printStackTrace();
        timer_delay = 0;
    }

    String burst_mode_value =      sharedPreferences.getString("preference_burst_mode", "1");
    try {
        n_burst = Integer.parseInt(burst_mode_value);
        if( MyDebug.LOG )
            Log.d(TAG, "n_burst: " + n_burst);
    }
    catch(NumberFormatException e) {
        if( MyDebug.LOG )
            Log.e(TAG, "failed to parse preference_burst_mode value: " +     burst_mode_value);
        e.printStackTrace();
        n_burst = 1;
    }
    remaining_burst_photos = n_burst-1;

    if( timer_delay == 0 ) {
        takePicture();
    }
    else {
        takePictureOnTimer(timer_delay, false);
    }
}

【问题讨论】:

    标签: android api android-fragments android-camera android-camera-intent


    【解决方案1】:

    如果您使用的是“原生”相机应用,并通过 Intent 与其通信,那么您需要首先定义 Uri,相机应用将在其中存储拍摄的图像。您必须在意图内将此 Uri 提供给相机应用程序:

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    
    cameraImageUri = FileUtils.getOutputMediaFileUriFromCamera(FileUtils.MEDIA_TYPE_IMAGE);
                            if (cameraImageUri != null) {
                                cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraImageUri);
                                getActivity().startActivityForResult(cameraIntent, CAMERA_CODE);
    }
    

    在这种情况下,在onActivityResult(int requestCode, int resultCode, Intent data) 回调期间,您必须将相同的 Uri 传递给 Aviary Activity:

    public void startAviaryForImageEdit(Uri imageUri) {
            Intent aviaryIntent = new Intent(getActivity(), FeatherActivity.class);
            aviaryIntent.putExtra(Constants.EXTRA_IN_API_KEY_SECRET, getString(R.string.aviary_key));
            aviaryIntent.setData(imageUri);
            getActivity().startActivityForResult(aviaryIntent, AVIARY_CODE);
        }
    

    【讨论】:

    • 什么是 FeatherActivity.class
    • 这是调用 Aviary 活动的旧方式,抱歉。现在,您可以使用Intent imageEditorIntent = new AviaryIntent.Builder(this) .setData(imageUri) .build() 来构建 Aviary 意图
    • 如何在android studio中导入aviary creative sdk
    • 按照本指南:link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    相关资源
    最近更新 更多