我正在创建一个图像处理应用程序,因此首先使用 android 平台 apis 来处理位图广告,然后将其发送到 flutter。我正在使用下面的代码将位图转换为字节 []
Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());
ByteBuffer allocate = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(allocate);
byte[] array = allocate.array();
Run Code Online (Sandbox Code Playgroud)
然后使用 Method Channel 作为 Uint8List 将其发送到 flutter 但当我将其读取为 Image.memory() 时。它给了我错误
解码图像失败。数据无效,或使用不受支持的格式编码。以下是我的主要活动的代码
package com.rahul.flutterappdomain;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import com.asksira.bsimagepicker.BSImagePicker;
import com.asksira.bsimagepicker.Utils;
import java.nio.ByteBuffer;
import io.flutter.app.FlutterFragmentActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class ActivityMain extends FlutterFragmentActivity implements BSImagePicker.OnSingleImageSelectedListener{
private static final String TAG = "DomainFilterFlutterApp";
private static final String CHANNEL = "com.rummy.io/filter"; …Run Code Online (Sandbox Code Playgroud)