[英]Convert a Bitmap to a 1bit Monochrome/Black and white Bitmap VB.net
I have a BMP file.. a basic barcode image.. When I go to save it Bitmap.save(File) it saves the BMP file all fine, but when I open it in photoshop its a indexed or RGB color bmp files.我有一个 BMP 文件.. 一个基本的条形码图像.. 当我 go 保存它 Bitmap.save(File) 它保存 BMP 文件一切正常,但是当我在 Photoshop 中打开它时,它是一个索引或 RGB 颜色 bmp 文件。
I need the file to be a 1bit black and white bmp file.我需要该文件是 1 位黑白 bmp 文件。 Its just a barcode...
它只是一个条形码...
I have been googling for hours, and I am unable to convert the c# examples (often uses Unsafe code) and all other examples are also just creating what photoshop sees as a RGB image.我已经在谷歌上搜索了几个小时,但我无法转换 c# 示例(通常使用不安全代码),所有其他示例也只是创建了 photoshop 所看到的 RGB 图像。
I need the file to be 1bit bmp as its loaded onto a ePaper device (like a kindle reader) and the device supplier has provided sample bitmaps that when loaded into photoshop as a mode Bitmap... not RGB or indexed.我需要将文件加载到 ePaper 设备(如 Kindle 阅读器)上时为 1 位 bmp,并且设备供应商提供了示例位图,当以 Bitmap 模式加载到 Photoshop 时......不是 RGB 或索引。
Any tips on how to get the file saved correctly?有关如何正确保存文件的任何提示?
HPD高压钠灯
here is sample conversion code in c#:这是 c# 中的示例转换代码:
private static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in codecs) {
if (codec.FormatID == format.Guid) {
return codec;
}
}
return null;
}
static void Main(string[] args)
{
var input = new Bitmap(@"d:\test.bmp");
var output = input.Clone(
new Rectangle(0, 0, input.Width, input.Height),
PixelFormat.Format1bppIndexed);
var encoder = GetEncoder(ImageFormat.Bmp);
var param = new EncoderParameter(Encoder.ColorDepth, 1L);
var paramss = new EncoderParameters(1);
paramss.Param[0] = param;
output.Save(@"d:\test_out.bmp", encoder, paramss);
}
and it produces bitmap mode bmp它产生 bitmap 模式 bmp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.