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;
}
}