我将NSData
对象中图像的转储作为输入。现在,我想从这个对象中提取图像的相关信息,比如像素数,没有。每像素等的位数
有人能告诉我如何从NSData
对象转储中提取这些信息吗?
P.S.:我已经看过NSData类的NSData文档,但无法分离出相关的方法。
发布于 2013-09-26 09:23:46
因此,最简单的方法是从UIImage
中实际构建NSData
对象,然后从UIImage
中提取信息。
UIImage* image = [UIImage imageWithData:yourData];
NSLog(@"Image is %dx%d",image.size.width, image.size.height);
如果您只对图像的属性感兴趣,但不想实际构建它的表示并只获取这些属性,那么CGImageSource
#import <ImageIO/ImageIO.h>
CGImageSourceRef imgSrc = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
size_t nbImages = CGImageSourceGetCount(imgSrc);
for(size_t idx=0; idx<nbImages; ++idx)
{
NSDictionary* props = (__bridge NSDictionary*)CGImageSourceCopyPropertiesAtIndex(imgSrc, idx, NULL);
NSLog(@"properties for image %lu in imageSource: %@", idx, props);
}
CFRelease(imgSrc);
要使其工作,显然要将ImageIO.framework添加到“与库连接的二进制文件”中
发布于 2013-09-26 09:17:34
将数据转换为UIImage,然后查看这 post。
UIImage *image = [UIImage imageWithData:data];
https://stackoverflow.com/questions/19024004
复制相似问题