我想在使用 PhotoEditorSDK Android 版编辑后将编辑后的照片分享到社交媒体网站,所以我创建了一个shareImage()
功能。
但是我不确定如何在共享功能中引用来自 PhotoEditorSDK 的编辑图像。目前,下面列出的代码我只是添加了从可绘制资源中获取的图像的虚拟图像。
目前,我放置在 PhotoEditorSDK photoeditor 视图中的共享按钮在按下时一直崩溃。
public class PhotoEditorActivity extends Activity implements PermissionRequest.Response {
private static final String FOLDER = "ArtCam";
public static int CAMERA_PREVIEW_RESULT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
super.onResume();
SettingsList settingsList = new SettingsList();
settingsList.getSettingsModel(EditorLoadSettings.class)
.setImageSourcePath(selectedImagePath, true) // Load with delete protection true!
.getSettingsModel(EditorSaveSettings.class)
.setExportDir(Directory.DCIM, FOLDER)
.setExportPrefix("result_")
.setSavePolicy(
EditorSaveSettings.SavePolicy.KEEP_SOURCE_AND_CREATE_ALWAYS_OUTPUT
);
new PhotoEditorBuilder(this)
.setSettingsList(settingsList)
.startActivityForResult(this, CAMERA_PREVIEW_RESULT);
shareImage();
}
private void shareImage() {
Intent shareIntent;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Share.png";
OutputStream out = null;
File file = new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path = file.getPath();
Uri bmpUri = Uri.parse("file://" + path);
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "#" + getPackageName());
shareIntent.setType("image/png");
startActivity(Intent.createChooser(shareIntent, "Share with"));
}