黑白图形上下文
我在 Quartz/Core-graphics 工作。 我正在尝试创建一个黑白、每像素 1b 的图形上下文。
我目前有一个带有灰度图像的 CGImageRef (实际上是黑白的)。 我想将它绘制到黑白 BitmapContext 中,这样我就可以取出位图并使用 CCITT-group 4 对其进行压缩。(出于某种原因,Quartz 不允许您以除 LZW 之外的任何 TIFF 格式保存)。
所以,我需要每像素 1 位的数据。 我认为绘制到 1bpp 上下文中就可以做到这一点。 但是,它不允许我创建上下文:
context = CGBitmapContextCreate (data,
pixelsWide,
pixelsHigh,
1,
pixelsWide/8,
CGColorSpaceCreateDeviceGray(),
kCGImageAlphaNone
);
是否有比灰色小的色彩空间?
I'm working in Quartz/Core-graphics. I'm trying to create a black and white, 1b per pixel graphics context.
I currently have a CGImageRef with a grayscale image (which is really black and white). I want to draw it into a black and white BitmapContext so I can get the bitmap out and compress it with CCITT-group 4. (For some reason Quartz won't let you save in any TIFF format other than LZW).
So, I need the 1bit per pixel data. I figure that drawing into a 1bpp context would do that. However, it won't let me create the context with:
context = CGBitmapContextCreate (data,
pixelsWide,
pixelsHigh,
1,
pixelsWide/8,
CGColorSpaceCreateDeviceGray(),
kCGImageAlphaNone
);
Is there a colorspace smaller than gray?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使支持 1 位位图,如果
pixelsWide
不是 8 的倍数,则每行的字节数不是整数:例如,如果您的图像是 12 像素宽,则每行的字节数是一个半。 您的除法表达式会将其截断为每行一个字节,这是错误的。但如果支持 1 位位图,他们不是。
Even if 1-bit bitmaps were supported, if
pixelsWide
is not a multiple of 8, then the number of bytes per row is not an integer: for example, if your image is 12 pixels wide, then the number of bytes per row is one and a half. Your division expression will truncate this to one byte per row, which is wrong.But that's if 1-bit bitmaps were supported, which they aren't.