0

我的颤振项目中有 2 项活动。首先是 Flutter 使用的 MainActivity,其次是 EditImageActivity。

现在我已经从颤动中调用了一个方法来创建从 MainActivity 到 EditImageActivity 的意图。

现在我想从 EditedImageActivity 中将编辑后的图像作为位图取回,但不知道如何将位图再次传递给颤动。

来自 Flutter 的 InvokeMethod

Future<void> _startStoryComposer() async {
    var platform = MethodChannel('com.allforty/story_composer');
    try {
      final String result = await platform.invokeMethod('story_composer', imagePath);
      debugPrint('Result: $result');
    } on PlatformException catch (e) {
      debugPrint("Error: '${e.message}'.");
    }
  }

维护.java

class MainActivity : FlutterActivity() {
    private val CHANNEL = "com.allforty/story_composer";

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        MethodChannel(flutterEngine?.dartExecutor?.binaryMessenger, CHANNEL)
            .setMethodCallHandler { call, result ->
                run {
                    if (call.method.equals("story_composer")) {
                        val imagePath:String = call.arguments as String
                        val intent = Intent(this, EditImageActivity::class.java)
                        intent.putExtra("imagePath", imagePath);
                        startActivity(intent);
                        result.success("Activity Started")
                    } else {
                        result.notImplemented();
                    }
                }
            }
    }
}

编辑图像活动.java

private void nextPressed() {
        SaveSettings saveSettings = new SaveSettings.Builder()
                .setCompressFormat(Bitmap.CompressFormat.PNG)
                .setCompressQuality(50)
                .setClearViewsEnabled(true)
                .setTransparencyEnabled(true)
                .build();

        mPhotoEditor.saveAsBitmap(saveSettings, new OnSaveBitmap() {
            @Override
            public void onBitmapReady(Bitmap saveBitmap) {
                //Want to pass the saveBitmap to Flutter Code
            }

            @Override
            public void onFailure(Exception e) {
                Toast.makeText(EditImageActivity.this, "Unable to Save", Toast.LENGTH_SHORT).show();
            }
        });
    }
4

0 回答 0