最终效果:

V1.8.2 20230419
文字生成单色BMP图片4.exe
默认1280*720  如果显示不全,请把宽和高加大  字体加大。

首先,用windows画板生成一张1*1白色单色图作为标准,数据如下:

数据解析参考:BMP图像文件完全解析 - 知乎

单色图有点不一样的是像数数据部分,是1bit一个点,0黑1白。4字节对齐是一样的。 比如上面是8000 0000   ,80即二进制1000 0000。因为是1*1,只有一个点有效,其它是4字节对齐。

再建一个2*1,变成C0    即二进制1100 0000

再建一个2*1,变成C0    即二进制1100 0000

再建一个1*2,变成8个数据,变成8000 0000 8000 0000 每一列都需要凑4字节的倍数

用C#生成单色图:

private void Form1_Load(object sender, EventArgs e){Bitmap bmp2 = new Bitmap(1, 1, PixelFormat.Format1bppIndexed);//其它bmp格式的画图数据//Graphics _Graphics = Graphics.FromImage(bmp2);//_Graphics.Clear(Color.Red);//_Graphics.Dispose();//bmp2.SetResolution( 72,72);//单色图数据Rectangle rect = new Rectangle(0, 0, bmp2.Width, bmp2.Height);System.Drawing.Imaging.BitmapData bmpData = bmp2.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp2.PixelFormat);// Get the address of the first line.IntPtr ptr = bmpData.Scan0;// Declare an array to hold the bytes of the bitmap.int bytes = Math.Abs(bmpData.Stride) * bmp2.Height;//error if bmpData.Widthbyte[] rgbValues = new byte[bytes];// Copy the RGB values into the array.System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);//Generate dots in random cells and show imagefor (int i = 0; i < bmp2.Height; i++){for (int j = 0; j < bmp2.Width; j += 8){byte b = 0;b = (byte)(b | ((byte)(1) << 7));//b = (byte)(b | ((byte)(1) << 6));//b = (byte)(b | ((byte)(1) << 5));//b = (byte)(b | ((byte)(1) << 4));//b = (byte)(b | ((byte)(1) << 3));//b = (byte)(b | ((byte)(1) << 2));//b = (byte)(b | ((byte)(1) << 1));//b = (byte)(b | ((byte)(1) << 0));rgbValues[i * bmpData.Stride + j / 8] = (byte)b;}}// Copy back values into the array.System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);// Unlock the bits.bmp2.UnlockBits(bmpData);//save bmpbmp2.Save("Test.bmp",ImageFormat.Bmp);}

任意语言完全用字节拼一张图:

JAVA C# Zxing生成的二维码数据转换为1bit的bmp下发到点阵终端。QRCode去白边,以bmp格式字节流发送,BMP图片解析_java图片转点阵_小黄人软件的博客-CSDN博客

谁有空帮填一下就行。JAVA写的部分。

             final int[] pixels = new int[width * height]; //假设有这么多图像数据,比如二维码矩阵final byte[] pixelsByte = new byte[ pixels.length/8 ]; //8个pixels合并到一个pixelsByte字节final byte[] bmpFile = new byte[ 0x3E+pixels.length/8 ]; //图片存储的位置+像素数据大小 整个文件buffArrays.fill(bmpFile, (byte) 0); //默认为0//0~1字节42、4d为B、M字符,表示BMP文件//2~5字节表示整个BMP文件的大小,小端模式,即0x0000003a,58字节//6~9字节是保留数据,一般都是0//10~13字节表示图片存储的位置//14~17字节为位图信息数据头,一般是40,即0x00000028。//18~21字节表示图像宽度,即0x00000001,//22~25字节表示图像高度。//26~27字节表示色彩平面数量,必须为1,即0x0001//28~29字节表示每个像素存储的位数(蓝色部分,0x0018,即24位)。//30~33字节为压缩方式,0表示不压缩//34~37字节表示原始位图数据的大小,即0x00000004,即4字节//38~41字节表示横向分辨率//42~45字节表示纵向分辨率//46~49字节表示调色板颜色数//50~53字节表示重要颜色数//54~57字节(红色部分)即原始的像素数据,这些才是最终需要显示到屏幕上的数据bmpFile[0]=0x42; //‘B’ bmpFile[1]=0x4d; //'M'bmpFile[10]=0x3E; //图片存储的位置System.arraycopy(pixelsBit,0,bmpFile,bmpFile[10],pixelsBit.length); //图像数据复制到buf位置WriteToFile(bmpFile,bmpFile.length);//二进制写入到文件

其它图片转为单色图:

 public void generateBMP(string contents, int width = 1280, int height = 720){if (contents.Length > 0){using (Bitmap bmp = GetStrBMPALL(contents, width, height)) // 获取待分析的字符位图{pictureBox2.Image = ConvertTo24bppTo1bpp(bmp);}}else{pictureBox2.Image = null;}pictureBox2.BringToFront(); //最前显示System.GC.Collect();//清内存 不然图片一直增加内存}//白底黑字public static Bitmap GetStrBMPALL(string str, int bmpWidth = 1280, int bmpHeight = 720) //str字符串  width单个宽度  height单个高度{str = str.Replace("\r", "");string[] lineList = str.Split('\n');Bitmap bmp = new Bitmap(bmpWidth, bmpHeight); // 新建位图变量Graphics g = Graphics.FromImage(bmp);Brush backgroud = Brushes.White; //点阵分隔线颜色g.FillRectangle(backgroud, new Rectangle(0, 0, bmpWidth, bmpHeight));//实心正方形 背景int y = 0;foreach (string line in lineList){int widthTemp = 0;foreach (char ch in line){g.DrawString(ch.ToString(), p.myFont, Brushes.Black, new PointF(widthTemp + p.xOffset, y + p.yOffset + 0.0F)); //new Font("宋体", 10)if ((int)ch <= 127) { widthTemp += p.width / 2; } else { widthTemp += p.width; } //如果是字符ASCII,宽度为8 如果是汉字,宽度为16}y += p.height;}//bmp.Save("out32.bmp");return bmp;}public static Bitmap ConvertTo24bppTo1bpp(Bitmap bmp, int pixelSize=1, int jg=0,int width=1280,int height=720) //bmp要显示的图  pixelSize单个点大小   jg点与点间隔 ,返回转换后的图{Bitmap bmp2 = new Bitmap(width, height, PixelFormat.Format1bppIndexed);         //Bitmap bmp2 = new Bitmap(@"Test.bmp", true);Rectangle rect = new Rectangle(0, 0, bmp2.Width, bmp2.Height);System.Drawing.Imaging.BitmapData bmpData = bmp2.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp2.PixelFormat);// Get the address of the first line.IntPtr ptr = bmpData.Scan0;// Declare an array to hold the bytes of the bitmap.int bytes = Math.Abs(bmpData.Stride) * bmp2.Height;//error if bmpData.Widthbyte[] rgbValues = new byte[bytes];// Copy the RGB values into the array.System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);//Generate dots in random cells and show imagefor (int i = 0; i < bmp.Height; i++){for (int j = 0; j < bmp.Width; j += 8){byte b = 0;b = (byte)(b | ((byte)((bmp.GetPixel(j + 0, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 7));b = (byte)(b | ((byte)((bmp.GetPixel(j + 1, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 6));b = (byte)(b | ((byte)((bmp.GetPixel(j + 2, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 5));b = (byte)(b | ((byte)((bmp.GetPixel(j + 3, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 4));b = (byte)(b | ((byte)((bmp.GetPixel(j + 4, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 3));b = (byte)(b | ((byte)((bmp.GetPixel(j + 5, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 2));b = (byte)(b | ((byte)((bmp.GetPixel(j + 6, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 1));b = (byte)(b | ((byte)((bmp.GetPixel(j + 7, i) == Color.FromArgb(0x0, 0, 0)) ? 1 : 0) << 0));rgbValues[i * bmpData.Stride + j / 8] = (byte)b;}}// Copy back values into the array.System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);// Unlock the bits.bmp2.UnlockBits(bmpData);bmp2.Save("out.bmp", ImageFormat.Bmp);return bmp2;}private void button1_Click(object sender, EventArgs e){p.xOffset = Convert.ToInt32(textBox5.Text);p.yOffset = Convert.ToInt32(textBox6.Text);p.width = Convert.ToInt32(textBox3.Text);p.height = Convert.ToInt32(textBox4.Text);generateBMP(textBox1.Text);}

C#生成单色bmp图片,转为单色bmp图片 任意语言完全用字节拼一张单色图,LCD取模 其它格式图片转为单色图相关推荐

  1. 【51单片机】0.96寸OLED取模教程(图片、汉字)+ 代码

    在文章开头必须值得一提的是 :文字和图片的取模并非是在网上随便找一篇文章如法炮制就行的 ,主要是看自己的代码读取是怎么写的,根据实际情况进行取模,才能实际在oled显示出来. 本文把oled工程模板代 ...

  2. 【工具】TFT彩屏图片点阵取模工具,Img2Lcd图片取模软件,图片生成c语言头文件...

    微信关注 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 最近玩童心派,上边有个128x128的彩屏,当然也是必须玩的,如何让彩屏显示图片呢?方 ...

  3. 怎么把图片转换成BMP格式

    1.选择要进行格式的图片,双击,进入[Windows照片查看器]2.点击[打开]选项,选择[画图],进入图片编辑窗口3.点击[选择],再在图片上选择要裁剪的区域,再点击[裁剪] 4.裁剪后,如果图片不 ...

  4. 【arduino】童芯派彩屏显示图片,图片取模后在TFT液晶显示

    微信关注 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 继续玩童芯派,128x128的彩屏应该是童芯派的一大亮点,150元(零售价)的开源硬件 ...

  5. Android与HEIF格式图片适配方法

    本文字数:1490字 预计阅读时间:8分钟 一. 什么是HEIF图片 HEIF (High Efficiency Image File Format)是由动态图像专家组(MPEG)在2013年推出的新 ...

  6. 使用Adobe Acrobat DC对.jpg和.png格式图片转换为.eps图片格式举例

    使用Adobe Acrobat DC对.jpg和.png等格式图片转换为.eps图片格式举例 在进行有的文档排版编辑时候(比如使用winEdt进行排版CTEX文件时候),需要添加.eps格式的图片,然 ...

  7. JPG格式如何转为PDF格式?快来学习如何转换

    图片是我们经常用到的一种便携式文件,像我们日常的照片或者是一些学习资料.工作资料都是图片形式的,我们经常会把这些图片发送给其他人,这时候就需要想一个简单的办法把图片一次性发送过去,所以我们可以将图片转 ...

  8. 设置图片格式为php,php 将bmp图片转为jpg等其他任意格式的图片

    php // 例子: $path = root . ' upload/2009/06/03/124401282315771. ' ; $pathall = $path . ' bmp ' ; $mi ...

  9. 纯C++实现24位bmp格式图片的读取和修饰

    问题:现有一张bmp图片,要求将它读取到程序中并进行灰度化.水平翻转.模糊.茶色滤镜四种效果的一种,并输出新图片,如下所示: 命令行输入: 其中: 参数1:-b/g/s/r,先后表示blur(模糊), ...

最新文章

  1. MMDetection3D:新一代通用3D目标检测平台
  2. library “libopencv_java4.so“ not found“
  3. SURF算法与源码分析、上
  4. Pixhawk(PX4)之驱动详解篇(0)_前期准备(招贤令)
  5. 腾讯 VS 阿里 VS 携程消息中间件设计方案及思路
  6. 使用halcon结合机械XY轴对相机进行9点标定
  7. c语言中sizeof是一个标准库函数,对C语言中的sizeof的介绍分析
  8. RAII(Resource Acquisition Is Initialization:资源获取即初始化)
  9. ORG LegacyCell for Mac - MS-20/Polysix音频合成器
  10. CF1067E Random Forest Rank
  11. 张超超OC基础回顾01_类的创建,申明属性,以及本质
  12. 细节复盘3 (文本折叠、文本尾行缩进截断)2020-8-2
  13. Python math 模块与 cmath 模块
  14. Arduino 编译出错:Pixy2I2C.h: No such file or directory
  15. 1.14 循环辅助语句
  16. WPF使用SaveFileDialog对话框保存文件时不要用DialogResult.OK判断对话框正常关闭
  17. java中的日志处理
  18. 阿D SQL注入工具常用的一些注入命令
  19. android 监听手机屏幕唤醒和睡眠广播
  20. 【合作】云计算基础架构【图】

热门文章

  1. 「snap」- 安装及卸载 @20210311
  2. linux mkfs 源码,源码安装mkfs.jffs2
  3. 在线编辑神器WebOffice + aspose/spire一起开创Office远程办公新时代
  4. 利用EVEREST Corporate Edition网络统计硬件配置信息
  5. STM32睡眠模式低功耗(停止模式)
  6. 【总结】Halcon图像拼接
  7. Vue2 or Vue3 or TS 使用最新版本 swiper/vue-awesome-swiper
  8. 一个webview崩溃的解决办法
  9. html5 video 在线视频,HTML5 视频(Video)
  10. 在linux下给编辑文件在哪里设置密码,技术|怎样在 Linux 中用 Vim 对文件进行密码保护...