我想将简单的UIImage转换为BitmapContext,但是找不到任何教程将UIImage转换为BitmapContext。请告诉我该怎么做?
谢谢!
最佳答案
可能这段代码可以帮助您
CGSize newSize = CGSizeMake(320, 400);
UIGraphicsBeginImageContext( newSize );
[imageView.image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(newImage);
[data writeToFile:@"foo.png" atomically:YES];
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);///save image in phone
OR For Bitmap.
CGContextRelease(context);
context = CGBitmapContextCreate (NULL,
image.size.width,
image.size.height,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaLast
);
CGColorSpaceRelease( colorSpace );
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
pixelData = CGBitmapContextGetData(context);