小笔记

作者: 我_是你哥 | 来源:发表于2022-11-28 11:39 被阅读0次

flutter,ios,android传值类型对应文档
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;
        }
    }

另一个方式采用C++base64

相关文章

网友评论

      本文标题:小笔记

      本文链接:https://www.haomeiwen.com/subject/scewxdtx.html