4
A
回答
6
您可以将UIImage转换为NSData对象,然后从那里提取字节数组。下面是一些示例代码:
UIImage *image = [UIImage imageNamed:@"image.png"];
NSString *byteArray = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
如果使用一个PNG图像可以使用UIImagePNGRepresentation功能如上图所示,或者如果使用的是JPEG图像,则可以使用UIImageJPEGRepresentation功能。文档可以使用UIImage Class Reference
0
NSData *data = UIImagePNGRepresentation(image);
可以图像转换成数据,现在通过使用getBytes:length:
或getBytes:range:
4
下面是一个简单的功能,适用于iOS从UIImage的转换为unsigned char *字节数组转换DAT到字节上 - >
+ (unsigned char*)UIImageToByteArray:(UIImage*)image; {
unsigned char *imageData = (unsigned char*)(malloc(4*image.size.width*image.size.height));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef imageRef = [image CGImage];
CGContextRef bitmap = CGBitmapContextCreate(imageData,
image.size.width,
image.size.height,
8,
image.size.width*4,
colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(bitmap, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
CGContextRelease(bitmap);
CGColorSpaceRelease(colorSpace);
return imageData;
}
相关问题
- 1. 签名的字节数组到UIImage
- 2. 转换字节数组到UIImage
- 3. 数据字节转换成UIImage的
- 4. 如何OData服务(OData的)字节数组转换成UIImage的
- 5. 如何将UIImage转换为字节数组或base64encoding?
- 6. 从UIImage获取字节
- 7. 制作的UIImage从字节
- 8. 作为字节发送UIImage?
- 9. 将字节数组转换回字节数组返回字节数组
- 10. 将字符串数组(字节值)转换为字节数组
- 11. 字节数组到
- 12. 从字节数组
- 13. 字节和字节数组的超类?
- 14. 获取字节数组字节元帅
- 15. 字节数组字符串
- 16. 读取字节数组与将字节数组写入文件
- 17. PHP字节数组为Base64(字节数组从Mssql中)
- 18. 将PNG压缩字节数组转换为BMP字节数组
- 19. 将Java字节数组转换为Python字节数组
- 20. 如何比较字节数组和字节数组列表?
- 21. 如何将Java字节数组转换为Scala字节数组?
- 22. 如何追加no。的字节数组到字节数组?
- 23. 如何从字节创建UIImage?
- 24. UIImage字节顺序已更改
- 25. 转换数字节数组
- 26. Python字节数组到位数组
- 27. 对象数组的字节数组
- 28. 对象数组到字节数组
- 29. 角色对象数组字节数组
- 30. Unsafe.As从字节数组到ulong数组
这对我很有帮助。谢谢你,苏哈尔你的帖子。 – Patricia