Skip to main content
You're viewing documentation for a previous version of this software.Switch to the latest stable version

Camera

The PhotoEditor SDK offers a camera implementation for Android to complement your editor, featuring essential camera components as well as live filters.

Camera tool

The PhotoEditor SDK offers a camera implementation for Android to complement your editor, featuring basic essential camera components as well as live filters.

In order to use our camera, you need to instantiate a CameraPreviewActivity using a CameraPreviewBuilder and present it. You can configure the camera to fit your needs by passing a SettingsList object to the builder. If no configuration is passed, the default setup is passed:

public class CameraDemoActivity extends Activity implements PermissionRequest.Response {
// Important permission request for Android 6.0 and above, don't forget to add this!
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
PermissionRequest.onRequestPermissionsResult(requestCode, permissions, grantResults);
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
public void permissionGranted() {}
@Override
public void permissionDenied() {
/* TODO: The Permission was rejected by the user. The Editor was not opened,
* Show a hint to the user and try again. */
}
public static int PESDK_RESULT = 1;
private SettingsList createPesdkSettingsList() {
// Create a empty new SettingsList and apply the changes on this referance.
SettingsList settingsList = new SettingsList();
// If you include our asset Packs and you use our UI you also need to add them to the UI,
// otherwise they are only available for the backend
// See the specific feature sections of our guides if you want to know how to add our own Assets.
settingsList.getSettingsModel(UiConfigFilter.class).setFilterList(
FilterPackBasic.getFilterPack()
);
settingsList.getSettingsModel(UiConfigText.class).setFontList(
FontPackBasic.getFontPack()
);
settingsList.getSettingsModel(UiConfigFrame.class).setFrameList(
FramePackBasic.getFramePack()
);
settingsList.getSettingsModel(UiConfigOverlay.class).setOverlayList(
OverlayPackBasic.getOverlayPack()
);
settingsList.getSettingsModel(UiConfigSticker.class).setStickerLists(
StickerPackEmoticons.getStickerCategory(),
StickerPackShapes.getStickerCategory()
);
// Set custom camera image export settings
settingsList.getSettingsModel(CameraSettings.class)
.setExportDir(Directory.DCIM, "SomeFolderName")
.setExportPrefix("camera_");
// Set custom editor image export settings
settingsList.getSettingsModel(SaveSettings.class)
.setExportDir(Directory.DCIM, "SomeFolderName")
.setExportPrefix("result_")
.setSavePolicy(SaveSettings.SavePolicy.RETURN_ALWAYS_ONLY_OUTPUT);
return settingsList;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openCamera();
}
private void openCamera() {
SettingsList settingsList = createPesdkSettingsList();
new CameraPreviewBuilder(this)
.setSettingsList(settingsList)
.startActivityForResult(this, PESDK_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, android.content.Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK && requestCode == PESDK_RESULT) {
// Editor has saved an Image.
EditorSDKResult data = new EditorSDKResult(intent);
data.notifyGallery(EditorSDKResult.UPDATE_RESULT & EditorSDKResult.UPDATE_SOURCE);
Log.i("PESDK", "Source image is located here " + data.getSourceUri());
Log.i("PESDK", "Result image is located here " + data.getResultUri());
// TODO: Do something with the result image
// OPTIONAL: read the latest state to save it as a serialisation
SettingsList lastState = data.getSettingsList();
try {
new IMGLYFileWriter(lastState).writeJson(new File(
Environment.getExternalStorageDirectory(),
"serialisationReadyToReadWithPESDKFileReader.json"
));
} catch (IOException e) { e.printStackTrace(); }
} else if (resultCode == RESULT_CANCELED && requestCode == PESDK_RESULT) {
// Editor was canceled
EditorSDKResult data = new EditorSDKResult(intent);
Uri sourceURI = data.getSourceUri();
// TODO: Do something...
}
}
}

Disable editor to open#

To prevent the 'editor screen' to open after taking a photo and to stay on 'capture mode' use this code:

settingsList.getSettingsModel(CameraSettings.class).setOpenEditorAfterCapture(false);

For more details, take a look at our getting started section.