gpt4 book ai didi

iphone - 在将高分辨率 pdf 绘制到 iphone 时保持图像质量?

转载 作者:太空狗 更新时间:2023-10-30 03:29:26 26 4
gpt4 key购买 nike

我有一个与 iPhone 中的 pdf 绘图相关的问题。当我在 ipad 中绘制 pdf 时它工作正常但在 iphone 中页面图像的质量不好。该图像在灰色背景处包含黑点。
谁能帮我解决这个问题?

谢谢。

- (UIImage *) imageForPageIndex:(NSUInteger)pageIndex {
UIImage *image = nil;
if ([delegate illustration_Enable])
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL,
pageSize.width,
pageSize.height,
8, /* bits per component*/
pageSize.width * 4, /* bytes per row */
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));

[self renderPageAtIndex:pageIndex OnContext:context];

CGImageRef cgimage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
image = [UIImage imageWithCGImage:cgimage];
CGImageRelease(cgimage);
}
else
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL,
pageSize.width,
pageSize.height,
8, /* bits per component*/
pageSize.width * 4, /* bytes per row */
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClipToRect(context, CGRectMake(0, 0, pageSize.width, pageSize.height));

[self renderPageAtIndex:pageIndex OnContext:context];


CGImageRef cgimage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
image = [UIImage imageWithCGImage:cgimage];

CGImageRelease(cgimage);
}


return image;

}

-(void)renderPageAtIndex:(int)index OnContext:(CGContextRef)ctx{

if ([delegate illustration_Enable])
{
if (index-1 == [imageList count]) {
return;
}
UIImage *image = nil;
image = [UIImage imageWithContentsOfFile:[imageList objectAtIndex:index-1]];
CGRect rect1 = CGRectMake(0, 0, image.size.width, image.size.height);
CGRect rect2 = CGContextGetClipBoundingBox(ctx);
CGAffineTransform transform = [self aspectFill:rect1 :rect2];
CGContextConcatCTM(ctx, transform);
CGContextDrawImage(ctx, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);

}
else
{
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, index);
CGRect rect1 = CGPDFPageGetBoxRect(page,kCGPDFMediaBox);
CGRect rect2 = CGContextGetClipBoundingBox(ctx);
CGAffineTransform transform;
if (takeBookmarkImg)
{
transform = [self aspectFill:rect1 :rect2];
}
else
{
transform = [self aspectFit:rect1 :rect2];
}
CGContextConcatCTM(ctx, transform);
CGContextDrawPDFPage(ctx, page);
}



}

- (CGAffineTransform) aspectFit:(CGRect)innerRect :(CGRect) outerRect {

scaleFactor = MIN(outerRect.size.width/innerRect.size.width, outerRect.size.height/innerRect.size.height);
baseScaleFactor = scaleFactor;
CGAffineTransform scale = CGAffineTransformMakeScale(scaleFactor, scaleFactor);
CGRect scaledInnerRect = CGRectApplyAffineTransform(innerRect, scale);

CGAffineTransform translation =
CGAffineTransformMakeTranslation((outerRect.size.width - scaledInnerRect.size.width) / 2 - scaledInnerRect.origin.x-(totalMoveX+moveX),
(outerRect.size.height - scaledInnerRect.size.height) / 2 - scaledInnerRect.origin.y+(totalMoveY+moveY));
return CGAffineTransformConcat(scale, translation);
}

.

最佳答案

这只是一个大胆的猜测,因为如果没有一些实际的屏幕截图很难说,但您没有在渲染代码中使用 CGContextSetInterpolationQuality。也许 CGContextSetInterpolationQuality(your_context, kCGInterpolationHigh) 解决了这个问题。

关于iphone - 在将高分辨率 pdf 绘制到 iphone 时保持图像质量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8652620/

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