0

我想在使用 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"));
    }
4

1 回答 1

0

请在此处查看演示代码https://github.com/imgly/pesdk-android-demo/blob/master/app/src/main/java/com/photoeditorsdk/android/app/MainActivity.java

您必须等待 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();
    }
}
于 2018-03-23T10:55:11.243 回答