gpt4 book ai didi

cocoa - 在 Cocoa 中将 PDF 转换为高分辨率图像的最佳方法

转载 作者:行者123 更新时间:2023-12-03 17:25:12 25 4
gpt4 key购买 nike

在 Cocoa 中将 PDF 转换为 300 dpi(例如)tiff 的最佳方法是什么?

我使用PDFImageRep创建NSImage,但我找不到放大分辨率的方法。

最佳答案

解决方案是为图像创建图形上下文并在该上下文中渲染 PDF 页面。创建上下文时,您指定所需的分辨率。此代码将完成这项工作:

+ (UIImage *) convertPDFPageToImage: (CGPDFPageRef) page withResolution: (float) resolution {   
CGRect cropBox = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
int pageRotation = CGPDFPageGetRotationAngle(page);

if ((pageRotation == 0) || (pageRotation == 180) ||(pageRotation == -180)) {
UIGraphicsBeginImageContextWithOptions(cropBox.size, NO, resolution / 72);
}
else {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(cropBox.size.height, cropBox.size.width), NO, resolution / 72);
}

CGContextRef imageContext = UIGraphicsGetCurrentContext();

[PDFPageRenderer renderPage:page inContext:imageContext];

UIImage *pageImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return pageImage;
}

取自这里:http://ipdfdev.com/2011/03/28/convert-a-pdf-page-to-image-on-the-iphone-and-ipad/

关于cocoa - 在 Cocoa 中将 PDF 转换为高分辨率图像的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7661479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com