解码 CGCreateImage 中忽略的值
我使用以下代码创建单色图像:
CGColorSpaceRef cgColorSpace = CGColorSpaceCreateDeviceGray();
CGImageRef cgImage = CGImageCreate (width, height, 1, 1, rowBytes, colorSpace, 0, dataProvider, decodeValues, NO, kCGRenderingIntentDefault);
其中 decodeValues
是 2 个 CGFloat
的数组,等于 {0,1}
。这给了我一个很好的图像,但显然我的数据(来自 PDF 图像蒙版)是白底黑字,而不是黑底白字。为了反转图像,我尝试将 decodeValues
的值设置为 {1,0}
,但这根本没有改变任何东西。实际上,无论我在 decodeValues
中输入什么无意义的值,我都会得到相同的图像。
为什么这里忽略 decodeValues
?如何反转黑白?
I am creating a monochrome image with the following code:
CGColorSpaceRef cgColorSpace = CGColorSpaceCreateDeviceGray();
CGImageRef cgImage = CGImageCreate (width, height, 1, 1, rowBytes, colorSpace, 0, dataProvider, decodeValues, NO, kCGRenderingIntentDefault);
where decodeValues
is an array of 2 CGFloat
's, equal to {0,1}
. This gives me a fine image, but apparently my data (which comes from a PDF image mask) is black-on-white instead of white-on-black. To invert the image, I tried to set the values of decodeValues
to {1,0}
, but this did not change anything at all. Actually, whatever nonsensical values I put into decodeValues
, I get the same image.
Why is decodeValues
ignored here? How do I invert black and white?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一些用于创建和绘制单色图像的代码。它与您的相同,但具有更多上下文(并且无需进行必要的清理):
如果我将解码数组更改为 CGFloatdecode[] = {0.0, 0.0}; 我总是得到黑色图像。
如果您已经尝试过并且没有任何效果(您说无论您使用什么值,您都会得到相同的图像),或者:您实际上并没有传递这些值,但您认为您是,或者:不知何故,您不是实际检查 CGImageCreate 的输出。
here's some code for creating and drawing a mono image. It's the same as yours but with more context (and without necessary cleanup):
If i change the decode array to
CGFloat decode[] = {0.0, 0.0};
i always get a black image.If you have tried that and it didn't have any effect (you say you get the same image whatever values you use), either: you aren't actually passing in those values but you think you are, or: somehow you aren't actually examining the output of CGImageCreate.