使用索引像素格式将文本写入图像 [英] Write text to image with indexed pixel format
问题描述
我有单色TIFF文件(1 bpp),我想写文字。当我将它们加载到System.Drawing.Image,并尝试从该图像实例化Graphics对象时,我收到错误,无法从具有索引像素格式的图像创建图形对象。
I have monochrome TIFF files (1 bpp) that I would like to write text to. When I load them into System.Drawing.Image, and try to instantiate a Graphics object from that image, I receive the error, "A Graphics object cannot be created from an image that has an indexed pixel format."
我可以将图像转换为非索引格式,例如JPEG,但结果图像尺寸非常大。
I can convert the images to a non-indexed format, such as JPEG, but then the resulting image size is very large.
我想在保持图像尺寸的同时实现这一目标。如何在不将这些图像转换为其他格式的情况下将文本写入这些图像?
I would like to accomplish this while keeping the image size down. How can I write text onto these images without converting them to another format?
推荐答案
使用Hans Passant留下的评论中的想法,我将这篇文章放在代码项目上: http:// www.codeproject.com/Articles/15186/Bitonal-TIFF-Image-Converter-for-NET
Using the idea in the comment left by Hans Passant, I located this article on code project: http://www.codeproject.com/Articles/15186/Bitonal-TIFF-Image-Converter-for-NET
调整此代码,我将图像转换为32bpp ,在该图像上写下文字,然后将其转换为1bpp。
Adapting this code, I converted the image to 32bpp, wrote the text on that image, then converted it to 1bpp.
这篇关于使用索引像素格式将文本写入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!