如何使用 CGBitmapContextCreateImage 获取优质图像
如何?... 我尝试使用 CGBitmapContextCreateImage() 获取高质量图像,并尝试使用以下代码来实现。
- (CGImageRef) imageForPageIndex:(NSUInteger)pageIndex {
NSUInteger width = pageSize.width;
NSUInteger height = pageSize.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger bytesPerPixel = 8;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
void* imageData = malloc(width * height * bytesPerPixel);
CGContextRef context = CGBitmapContextCreate(imageData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, pageSize.width * 2, pageSize.height * 2, 8, pageSize.width * 8, colorSpace, kCGImageAlphaPremultipliedLast | CGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, pageSize.height);
CGContextConcatCTM(context, flipVertical);
[dataSource renderPageAtIndex:pageIndex inContext:context];
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRelease(context);
[UIImage imageWithCGImage:image];
CGImageRelease(image);
return image;
}
但是,我无法获得模糊图像,因此渲染图像和原始屏幕图像之间存在一些差异。 我不知道原因。 请帮我...
How?...
I am tring to get High Quality image using CGBitmapContextCreateImage() and tried to do it with the following code.
- (CGImageRef) imageForPageIndex:(NSUInteger)pageIndex {
NSUInteger width = pageSize.width;
NSUInteger height = pageSize.height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger bytesPerPixel = 8;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
void* imageData = malloc(width * height * bytesPerPixel);
CGContextRef context = CGBitmapContextCreate(imageData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, pageSize.width * 2, pageSize.height * 2, 8, pageSize.width * 8, colorSpace, kCGImageAlphaPremultipliedLast | CGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, pageSize.height);
CGContextConcatCTM(context, flipVertical);
[dataSource renderPageAtIndex:pageIndex inContext:context];
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRelease(context);
[UIImage imageWithCGImage:image];
CGImageRelease(image);
return image;
}
But, i couldn't get the blur image, so there is some difference between the rendered image and original screen image.
I can't know the reason.
Please help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论