UnityNativeGallery插件遇到红色问号
最近要用unity 获取相册照片遇到一个问题,貌似有些照片 显示红色问号,只有在iOS 上 会出现,安卓则正常,猜测iOS 对某些图片(png)的解析失败,为了解决这个问题,把拉起来的图片 格式统一改成了 jpg ,改了NativeGallery 这个 .mm 文件的代码,就是传给C# 的时候,改一下 1、大概一千零几行代码左右 改之前 :
dispatch_group_notify( group, dispatch_get_main_queue(),
^{
if( !pickingMultipleFiles )
UnitySendMessage( "NGMediaReceiveCallbackiOS", "OnMediaReceived", [self getCString:resultPaths[0]] );
else
UnitySendMessage( "NGMediaReceiveCallbackiOS", "OnMultipleMediaReceived", [self getCString:[resultPaths componentsJoinedByString:@">"]] );
});
改之后 :
dispatch_group_notify( group, dispatch_get_main_queue(),
^{
if( !pickingMultipleFiles )
{
NSData *imageData = [NSData dataWithContentsOfFile:resultPaths[0]];
UIImage *originImage = [UIImage imageWithData:imageData];
NSData *newIgdata= UIImageJPEGRepresentation(originImage, 1);
[newIgdata writeToFile:resultPaths[0] atomically:YES];
UnitySendMessage( "NGMediaReceiveCallbackiOS", "OnMediaReceived", [self getCString:resultPaths[0]] );
}
else
UnitySendMessage( "NGMediaReceiveCallbackiOS", "OnMultipleMediaReceived", [self getCString:[resultPaths componentsJoinedByString:@">"]] );
});
2、还有一处 七百多行 改之前 :
popup = nil;
imagePicker = nil;
imagePickerState = 2;
UnitySendMessage( "NGMediaReceiveCallbackiOS", "OnMediaReceived", [self getCString:resultPath] );
[picker dismissViewControllerAnimated:NO completion:nil];
改之后 :
popup = nil;
imagePicker = nil;
imagePickerState = 2;
NSData *imageData = [NSData dataWithContentsOfFile:resultPath];
UIImage *originImage = [UIImage imageWithData:imageData];
NSData *newIgdata= UIImageJPEGRepresentation(originImage, 1);
[newIgdata writeToFile:resultPath atomically:YES];
UnitySendMessage( "NGMediaReceiveCallbackiOS", "OnMediaReceived", [self getCString:resultPath] );
[picker dismissViewControllerAnimated:NO completion:nil];
OK,就这两处就可以了
|