如何从UIImage获取NSData
1个回答
2015-11-13
展开全部
从UIImage 取出CGImageRef, 然后画到一个新的CGImageRef, 然后就可以的到原始数据
//UIImage* ImageA;
CGImageRef image = [ImageA CGImage];
CGSize image_size = ImageA.size;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void* data = malloc(image_size.width * image_size.height * 4);
CGContextRef context =
CGBitmapContextCreate(data, image_size.width, image_size.height, 8, 4 * image_size.width, colorSpace,
kCGImageAlphaPremul www.hbbz08.com tipliedLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(context, CGRectMake(0, 0, leftwidth, image_size.height), image);
/*
data中就是你要得原始bmp图了, 没有文件头
*/
CGContextRelease(context);
free(data);
//UIImage* ImageA;
CGImageRef image = [ImageA CGImage];
CGSize image_size = ImageA.size;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void* data = malloc(image_size.width * image_size.height * 4);
CGContextRef context =
CGBitmapContextCreate(data, image_size.width, image_size.height, 8, 4 * image_size.width, colorSpace,
kCGImageAlphaPremul www.hbbz08.com tipliedLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(context, CGRectMake(0, 0, leftwidth, image_size.height), image);
/*
data中就是你要得原始bmp图了, 没有文件头
*/
CGContextRelease(context);
free(data);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询