gpt4 book ai didi

pdf - CGContextDrawRadialGradient 不在 PDF 中呈现 alpha?

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

我有下面的图,它呈现了一个中心全彩色的圆,边缘的 alpha 渐变为 0。将其绘制到屏幕上时,它看起来很完美。但是,当我在 PDF 上下文 (CGPDFContextCreate) 中绘制相同的东西时,整个圆圈变得不透明。如果我在 PDF 中绘制任何其他常规路径,则 alpha 渲染罚款。所以只是渐变不起作用。这是错误还是我遗漏了什么?

        CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
size_t num_locations = 2;
CGFloat locations[2] = { 1.0, 0.0 };

CGColorRef color = [[UIColor redColor]CGColor];
CGFloat *k = (CGFloat *)CGColorGetComponents(color);
CGFloat components[8] = { k[0], k[1], k[2], 0.0, k[0], k[1], k[2], 1.0 };

CGGradientRef myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, num_locations);

CGPoint c = CGPointMake(160, 160);
CGContextDrawRadialGradient(pdfContext, myGradient, c, 0, c, 60, 0);

最佳答案

苹果技术支持官方回复:

Quartz ignores the alpha value of colors in gradients (or shadings) when capturing a gradient (or shading) to a PDF document and instead treats all colors as if they are completely opaque. In addition, Quartz ignores the global alpha in the context when it records gradients (or shadings) into a PDF document. One possible work-around is to capture a shading as bits using a bitmap context and use the resulting bits to create a CGImage that you draw through the clipping area. This produces pre-rendered gradients (or shadings) but does capture the alpha content into a PDF document. You should not perform this pre-rendering for gradients (or shadings) that don't contain alpha.

关于pdf - CGContextDrawRadialGradient 不在 PDF 中呈现 alpha?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9151915/

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