我想在使用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"));
}
答案 0 :(得分:0)
您必须等待onActivityResult才能获取resultPath
@Override
protected void onActivityResult(int requestCode, int resultCode, android.content.Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == CAMERA_PREVIEW_RESULT) {
String resultPath = data.getStringExtra(ImgLyIntent.RESULT_IMAGE_PATH);
if (resultPath != null) {
// Add result file to Gallery
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(resultPath))));
}
//TODO: Share the resultPath file
} else if (resultCode == RESULT_CANCELED && requestCode == CAMERA_PREVIEW_RESULT && data != null) {
String sourcePath = data.getStringExtra(ImgLyIntent.SOURCE_IMAGE_PATH);
Toast.makeText(PESDK.getAppContext(), "Editor canceled, sourceType image is:\n" + sourcePath, Toast.LENGTH_LONG).show();
}
}