// // Created by Yohom Bao on 2019/11/22. // #import "UIImageHandler.h" extern BOOL enableLog; void UIImageHandler(NSString *method, id rawArgs, FlutterResult methodResult) { // UIImage::getData if ([@"UIImage::getData" isEqualToString:method]) { NSDictionary *args = (NSDictionary *) rawArgs; UIImage *target = (UIImage *) args[@"__this__"]; if (target != nil && (NSNull*) target != [NSNull null]) { NSData *data = UIImageJPEGRepresentation(target, 100); methodResult([FlutterStandardTypedData typedDataWithBytes:data]); } else { methodResult([FlutterError errorWithCode:@"目标对象为nul" message:@"目标对象为nul" details:@"目标对象为nul"]); } } // 创建UIImage else if ([@"UIImage::createUIImage" isEqualToString:method]) { NSDictionary *args = (NSDictionary *) rawArgs; FlutterStandardTypedData *bitmapBytes = (FlutterStandardTypedData *) args[@"bitmapBytes"]; UIImage *bitmap = [UIImage imageWithData:bitmapBytes.data scale:[UIScreen mainScreen].scale]; methodResult(bitmap); } // 创建UIImage else if ([@"UIImage::createWithPath" isEqualToString:method]) { NSDictionary *args = (NSDictionary *) rawArgs; NSString *resource = (NSString *) args[@"resource"]; NSString *type = (NSString *) args[@"type"]; NSString *fileName = (NSString *) args[@"fileName"]; NSString *path = [[NSBundle mainBundle] pathForResource:resource ofType:type]; path = [path stringByAppendingPathComponent:fileName]; UIImage *bitmap = [UIImage imageWithContentsOfFile:path]; methodResult(bitmap); } // 批量创建UIImage else if ([@"UIImage::createUIImage_batch" isEqualToString:method]) { NSArray *> *argsBatch = (NSArray *> *) rawArgs; NSMutableArray *resultList = [NSMutableArray array]; for (NSUInteger __i__ = 0; __i__ < argsBatch.count; __i__++) { NSDictionary *args = argsBatch[__i__]; FlutterStandardTypedData *bitmapBytes = (FlutterStandardTypedData *) args[@"bitmapBytes"]; UIImage *bitmap = [UIImage imageWithData:bitmapBytes.data scale:[UIScreen mainScreen].scale]; [resultList addObject:bitmap]; } methodResult(resultList); } else { methodResult(FlutterMethodNotImplemented); } }