将照片编辑 AVIORY API 与相机应用集成
integrate photo editing AVIORY API with camera app
我想将第 3 方照片编辑 AVIORY api 与我正在开发的本机相机应用程序集成,但我无法做到这一点。 api 在拍摄照片后工作。请告诉我如何实现这个 AVIORY API。这是link到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);
}
}
如果您正在使用 "native" 相机应用程序,并通过意图与其通信,那么您需要首先定义 Uri,相机应用程序将在其中存储拍摄的图像。您必须在 intent 内将此 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);
}
我想将第 3 方照片编辑 AVIORY api 与我正在开发的本机相机应用程序集成,但我无法做到这一点。 api 在拍摄照片后工作。请告诉我如何实现这个 AVIORY API。这是link到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);
}
}
如果您正在使用 "native" 相机应用程序,并通过意图与其通信,那么您需要首先定义 Uri,相机应用程序将在其中存储拍摄的图像。您必须在 intent 内将此 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);
}