我是靠谱客的博主 激情蛋挞,最近开发中收集的这篇文章主要介绍OLED显示图片,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

今天一个朋友问我取字模相关的问题,我之前也没怎么接触取字模的软件,今天顺便试了试用imag2lcd取出bmp文件,然后通过stm32和oled来显示图片。

首先点击打开,打开一张你要显示的图片(有些图片格式不支持),最大宽度和高度要用128*64,按照下图配置好后,记得调节亮度和对比度,使其更加清晰,然后将其保存。注意下方的输出图像(54,64)

打开pctolcd2002,模式中选择图形模式,点击软件中文件夹一样的图形用pctolcd2002打开保存好的bmp文件,(记住选项,帮助栏下面的图像大小),我这儿是(54*64)——软件问题看不清还可以在前面的imag2lcd软件下方的输出图像查看。

在这里插入图片描述

然后是字模的配置,按照代码要求如图配置

在这里插入图片描述

然后点击生成字模并将其放入准备好的数组里,下面是我取出的小猪佩奇

unsigned char nao1[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x40,
0xC0,0x40,0xC0,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0xE0,0x30,0x18,0x08,0x98,
0xF0,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x7E,
0xC1,0x86,0x86,0xCC,0x4C,0x20,0x1C,0x03,0x00,0x00,0x1C,0x2A,0x3E,0x2B,0x1D,0xE1,
0x53,0xF3,0x52,0xA4,0x46,0x0B,0x18,0x1C,0x23,0xC1,0xA1,0x31,0x0F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x06,0x04,0xE8,0x38,0x18,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0xC0,0x20,0x10,0x10,0x10,0x20,
0xC1,0x06,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xE0,0xC0,0x00,0x00,0x00,0x00,
0x00,0x3F,0x60,0xC0,0x83,0x04,0x08,0x18,0x10,0x10,0x10,0x18,0x08,0x04,0x00,0x00,
0x01,0x02,0x04,0x04,0x04,0x82,0xC1,0x38,0x0F,0x00,0x00,0x00,0x00,0xC0,0xE0,0x80,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x01,0x01,0x03,0x03,0x06,0x84,0xFC,0x1C,0x06,0x01,0x01,0x03,0x02,0x06,0x04,0x04,
0x04,0x0C,0x0C,0x0C,0x0C,0x0C,0x04,0x04,0x06,0x02,0x03,0x03,0x0E,0x78,0xCC,0x06,
0x86,0x43,0x43,0x81,0x03,0x03,0x80,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0xA0,0x20,0x20,0x20,0x20,0x40,0xC0,0x00,0x00,0xF8,0x1F,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x03,0xFE,0xE1,0x22,0x22,0x12,0x0B,0x0F,0xC0,0x60,0x10,0x10,
0x10,0x90,0x60,0x00,0x00,0x00,0x80,0x40,0x41,0x42,0x42,0x42,0x42,0x43,0xC0,0x06,
0x07,0x04,0x04,0x04,0xC4,0x44,0x44,0x74,0x14,0x1C,0x1C,0xF4,0x04,0x04,0x04,0x04,
0x84,0x44,0x44,0x74,0x14,0x1C,0x1C,0xF4,0x04,0x04,0x04,0x04,0x07,0x00,0x02,0x60,
0x60,0xA0,0x21,0x21,0x21,0x21,0x21,0x20,0xC0,0x00,0x00,0x07,0x08,0x08,0x08,0x08,
0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x04,0x04,
0x04,0x07,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x04,0x04,0x04,0x07,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x04,0x04,0x03,0x00,
};

这是朋友发来的工程文件,商家已经写好的代码,真香

/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
{ 	
 unsigned int j=0;
 unsigned char x,y;
  
  if(y1%8==0) y=y1/8;      
  else y=y1/8+1;
	for(y=y0;y<y1;y++)
	{
		OLED_Set_Pos(x0,y);
    for(x=x0;x<x1;x++)
	    {      
	    	OLED_WR_Byte(BMP[j++],OLED_DATA);	    	
	    }
	}
} 

函数有四个形参,x和y可以理解为行和列,x0是要显示的开始列,x1为结束列,y0 为起始行,y1为结束行(这里的行是8的倍数),如果上方的输出图像大小为(54,64),那么起始列和结束列的差必须为54,也就是x1-x0=54,同理(y1-y0)*8=64。最后主函数调用OLED_DrawBMP();函数,即可显示啦。

 OLED_DrawBMP(73,0,127,8,nao1);	//靠右显示	
 OLED_DrawBMP(0,0,54,8,nao1);//靠左显示	

以上就是全部的过程了,如果有错误还请大神指出,哪里不清晰可以直接评论交流,需要相关软件或程序可以直接评论哦!

最后

以上就是激情蛋挞为你收集整理的OLED显示图片的全部内容,希望文章能够帮你解决OLED显示图片所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部