gpt4 book ai didi

iphone - 我们可以将 NSDecimal 值转换为 UIImage 吗?

转载 作者:可可西里 更新时间:2023-11-01 05:13:44 25 4
gpt4 key购买 nike

我正在发送一些数据和 UIImage(将 UIImage 转换为 NSData)发送到服务器,我的客户端正在返回我们发送的响应。

但是,这里我的客户给出了如下格式的 UIImage

FaceImage":[255,216,255,224,0,16,74,70,73,70,0,1,1,1,1,44,1,44,0,0,255,219,0,67,0,8,6,6,7,6,5,8,7,7,7,9,9,8,10,12,20,13,12,11,11,12,25,18,19,15,20,29,26,31,30,29,26,28,28,32,36,46,39,32,34,44,35,28,28,40,55,41,44,48,49,52,52,52,31,39,57,61,56,50,60,46,51,52,50,255,219,0,67,1,9,9,9,12,11,12,24,13,13,24,50,.................................................................]

我测试了上面的一个来测试我们通过使用这个日志得到了什么

NSLog(@"testingImageView.image is =%@",[[[datadic valueForKey:@"FaceImage"] objectAtIndex:0] class]);

响应是:testingImageView.image is =NSDecimal。

如果是NSData我们可以转换成UIImage,但是这里是十进制格式。

我的问题是,我可以将它转换为 UIImage 吗?即,UIImage 的十进制值。

提前致谢。

最佳答案

您的响应包含十进制数字形式的所有图像字节。 (255,216 是十六进制的 FF,D8,表示 JPEG 图像的开始)。下面的代码应该可以根据数字数组创建 UIImage:

NSArray *array = [datadic objectForKey:@"FaceImage"];
NSMutableData *imageData = [NSMutableData dataWithLength:[array count]];
uint8_t *imageBytes = [imageData mutableBytes];
for (NSUInteger i = 0; i < [array count]; i++) {
imageBytes[i] = [array[i] unsignedCharValue];
}
UIImage *image = [UIImage imageWithData:imageData];

关于iphone - 我们可以将 NSDecimal 值转换为 UIImage 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15473587/

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