gpt4 book ai didi

iphone - 使用 ImageIO 在 iOS 上创建渐进式 jpeg 在设备上产生 block 状结果

转载 作者:技术小花猫 更新时间:2023-10-29 10:54:16 27 4
gpt4 key购买 nike

我正在尝试从 UIImage 对象创建渐进式 jpeg,这是我的代码

NSMutableData *data = [NSMutableData data];

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Caches/test.jpg"];

CFURLRef url = CFURLCreateWithString(NULL, (CFStringRef)[NSString stringWithFormat:@"file://%@", path], NULL);
CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL);
CFRelease(url);

NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge id)kCFBooleanTrue, kCGImagePropertyJFIFIsProgressive,
nil];

NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:.7], kCGImageDestinationLossyCompressionQuality,
jfifProperties, kCGImagePropertyJFIFDictionary,
nil];

CGImageDestinationAddImage(destination, ((UIImage*)object).CGImage, (__bridge CFDictionaryRef)properties);
CGImageDestinationFinalize(destination);
CFRelease(destination);

这在模拟器中运行时效果很好,但不幸的是在设备上会产生粗大/ block 状的结果:

chunky/blocky result.

对发生的事情有什么想法吗?我会恢复使用 UIImageJPEGRepresentation 作为最后的手段,我真的需要渐进式 JPEG。

最佳答案

好消息:我刚刚在 iPhone 4 上进行了测试,图像看起来很棒:

NSDictionary *jfifProperties = [NSDictionary dictionaryWithObjectsAndKeys:
@72, kCGImagePropertyJFIFXDensity,
@72, kCGImagePropertyJFIFYDensity,
@1, kCGImagePropertyJFIFDensityUnit,
nil];

(使用新的文字语法)。

很好JFIF reference这些密度选项的含义。

关于iphone - 使用 ImageIO 在 iOS 上创建渐进式 jpeg 在设备上产生 block 状结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10829100/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com