小筆記

flutter,ios,android傳值類型對(duì)應(yīng)文檔
Flutter

   File file = File(widget.imageList.first);
    Uint8List bytes = await file.readAsBytes();
  //封裝的傳值的類
    imageBytes = await iva.getCropedImage(bytes);
Future<Uint8List> getCropedImage(Uint8List imageBytes) async{
    late Uint8List bytes;
    try{
      bytes =  await _methodChannel.invokeMethod("getCropedImage",imageBytes);
    }on PlatformException catch (e){
      bytes = Uint8List(0);
      print("失敗:${e.message}") ;
    }
    return bytes;
  }
}

iOS

            FlutterStandardTypedData *bytesList = call.arguments;
            UIImage *image = [UIImage imageWithData:bytesList.data];
            NSData *imageData = [self image2Data:image];
            FlutterStandardTypedData *rList = [FlutterStandardTypedData typedDataWithBytes:imageData];
- (NSData *)image2Data:(UIImage *)image{
    NSDictionary *options = @{(__bridge NSString *)kCGImageSourceShouldCache : @NO,
                              (__bridge NSString *)kCGImageSourceShouldCacheImmediately : @NO
                              };
    NSMutableData *data = [NSMutableData data];
    CGImageDestinationRef destRef = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)data, kUTTypeJPEG, 1, (__bridge CFDictionaryRef)options);
    CGImageDestinationAddImage(destRef, image.CGImage, (__bridge CFDictionaryRef)options);
    CGImageDestinationFinalize(destRef);
    CFRelease(destRef);
    return data;
}

android

                    byte[] bytes = (byte[]) call.arguments;
                    Bitmap bitmap = Bytes2Bimap(bytes);
                    byte[] rbytes = Bitmap2Byte(bitMap);
                    result.success(rbytes);
    public Bitmap Bytes2Bimap(byte[] b) {
        if (b.length != 0) {
            return BitmapFactory.decodeByteArray(b, 0, b.length);
        } else {
            return null;
        }
    }

    public byte[] Bitmap2Byte(Bitmap bitmap){
        if (bitmap != null){
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            return baos.toByteArray();
        }else {
            return null;
        }
    }

另一個(gè)方式采用C++base64

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容