项目中可能会用到12864液晶(或者其它分辨率的),用C#模拟了一下显示效果

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//WinForm中需要一个picturebox控件
namespace emulateLCD
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            graphics = this.pictureBox1.CreateGraphics();
            bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
            int i, j;
            for (i = 0; i < 64; i++)
            {
                for (j = 0; j < 16; j++)
                {
                    data[i, j] = 0x00;
                }
            }
        }
        private Bitmap bmp;
        private Graphics graphics;
        private byte[,] data = new byte[64, 16];//12864图形数据数组
        byte[] tab =
        {
        0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x20,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,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,
        0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x40,
        0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x40,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x01,0xC2,0x40,
        0x00,0x00,0x00,0x06,0x30,0x01,0xE0,0x00,0x00,0x2A,0x00,0x00,0xD8,0x01,0xC6,0x40,
        0x00,0x00,0x00,0x0F,0x7B,0x63,0xE0,0x00,0x00,0x22,0x00,0x01,0x24,0x00,0x04,0x40,
        0x00,0x00,0x00,0x0F,0xFB,0x63,0x07,0x34,0x00,0x14,0x00,0x01,0x04,0x00,0x08,0xF8,
        0x00,0x00,0x00,0x0D,0xDB,0x63,0x01,0xBC,0x00,0x08,0x00,0x00,0x88,0x00,0x1F,0x40,
        0x00,0x04,0x00,0x0C,0x1B,0x63,0x07,0xB0,0x00,0x00,0x00,0x00,0x50,0x00,0x30,0x40,
        0x00,0x06,0x00,0x0C,0x1B,0x63,0xED,0xB0,0xDB,0x00,0x01,0x00,0x20,0x00,0x00,0x40,
        0x00,0x02,0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x40,
        0x00,0x02,0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x40,
        0x00,0x02,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x42,
        0x00,0x02,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x03,0xFF,0xFE,
        0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x05,0x00,0x00,0x00,0x40,
        0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x0A,0x80,0x00,0x00,0x40,
        0x00,0x02,0x20,0x00,0x00,0x0A,0x00,0x00,0xFF,0xF8,0xE0,0x05,0x00,0x00,0x00,0x40,
        0x00,0x82,0x20,0x06,0xC0,0x15,0x00,0x1F,0xFF,0xFF,0xC0,0x02,0x00,0x00,0x00,0x40,
        0x00,0x82,0x30,0x09,0x20,0x11,0x00,0xFB,0xFF,0xE1,0xF8,0x00,0x00,0x00,0x00,0x40,
        0x01,0x82,0x10,0x08,0x20,0x0A,0x03,0x9F,0x00,0x9E,0x3E,0x00,0x00,0x00,0x00,0x40,
        0x01,0x02,0x10,0x04,0x40,0x04,0x0E,0x70,0x00,0x81,0xC7,0x80,0x01,0x40,0x00,0x40,
        0x01,0x02,0x08,0x02,0x80,0x00,0x1D,0x80,0x00,0xE0,0x61,0xE0,0x02,0xA0,0x00,0x40,
        0x02,0x02,0x08,0x01,0x00,0x00,0x77,0x9F,0xFC,0xF0,0x18,0xF8,0x02,0x20,0x00,0x40,
        0x06,0x02,0x08,0x00,0x00,0x01,0xDF,0x00,0x00,0xF3,0x0C,0x3C,0x01,0x40,0x00,0x00,
        0x0C,0x06,0x0C,0x00,0x00,0x03,0x9E,0x00,0x00,0xF8,0x06,0x1E,0x00,0x80,0x00,0x00,
        0x00,0x44,0x04,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,
        0x00,0x6C,0x06,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,
        0x00,0x38,0x03,0x00,0x00,0x7E,0xFF,0xFF,0xFF,0xFF,0xFF,0x83,0xC0,0x00,0x00,0x00,
        0x00,0x18,0x00,0x00,0x0F,0xFD,0xFF,0xFF,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x78,0x00,
        0x00,0x00,0x00,0x00,0x3F,0x81,0xFF,0x00,0x00,0x00,0x00,0x1F,0xF0,0x00,0x48,0x00,
        0x00,0x00,0x00,0x00,0xFE,0xF0,0x00,0x00,0x01,0x00,0x00,0xC0,0x1C,0x00,0x44,0x00,
        0x00,0x03,0x00,0x03,0xC0,0x07,0x80,0x00,0x03,0xE2,0x07,0x00,0x1C,0x00,0x46,0x00,
        0x00,0x06,0x00,0x03,0x80,0x03,0x40,0x00,0x03,0xE0,0x0C,0x00,0x0E,0x00,0x42,0x00,
        0x00,0x1C,0x00,0x07,0x00,0x00,0xC0,0x00,0x00,0x20,0x18,0x00,0x07,0x00,0x42,0x00,
        0x00,0xF0,0x00,0x09,0x01,0x80,0x60,0x00,0x00,0x20,0x73,0x9F,0x03,0x80,0x42,0x00,
        0x00,0x10,0x00,0x1E,0x0F,0xF2,0x20,0x00,0x00,0x20,0x67,0xFF,0xC1,0xC0,0x46,0x00,
        0x00,0x10,0x00,0x1E,0x1F,0xF9,0x30,0x00,0x00,0x20,0xEF,0xFF,0xE0,0xE0,0x7C,0x00,
        0x03,0xFC,0x00,0x38,0x3F,0xFC,0x90,0x00,0x00,0x20,0xCB,0xFF,0xF9,0xF0,0xFF,0x00,
        0x00,0x10,0x00,0x7F,0x7F,0xFE,0x10,0x00,0x00,0x20,0xDB,0xFF,0xFF,0xF0,0x41,0xC0,
        0x00,0x10,0x00,0x6E,0xF9,0xBF,0x10,0x00,0x00,0x20,0xF7,0xED,0xFF,0xF0,0x40,0x60,
        0x00,0x11,0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x40,0x30,
        0x03,0xFF,0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0xC0,0x10,
        0x00,0x10,0x00,0x38,0xFC,0x3F,0x18,0x00,0x00,0x20,0x87,0xE0,0xFD,0xC0,0x80,0x08,
        0x00,0x20,0x00,0x38,0xF1,0x8F,0x18,0x00,0x1F,0xE7,0x87,0x9C,0x7D,0xC0,0x80,0x08,
        0x00,0x60,0x00,0x1C,0xFE,0x1F,0x81,0xFF,0xFF,0xC0,0x0F,0xE0,0xFF,0x80,0x80,0x04,
        0x00,0x40,0x00,0x0C,0xFC,0x3F,0x80,0x00,0x00,0x00,0x0F,0xE1,0xF8,0x00,0x80,0x04,
        0x01,0x80,0x00,0x00,0xF9,0xBF,0xE0,0x00,0x00,0x00,0x03,0xEC,0xF6,0x01,0x80,0x0C,
        0x01,0xC3,0x00,0x00,0xF9,0xBF,0x00,0x00,0x00,0x00,0x00,0xFF,0xCC,0x01,0x80,0x18,
        0x00,0x3F,0x80,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x81,0xF0,
        0x00,0x00,0xC0,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
        0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x20,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,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,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,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,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

        };

        private void Form1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {

        }
        protected override void OnPaint(PaintEventArgs e)
        {

        }

        private void Form1_Click(object sender, EventArgs e)
        {
            DrawGraph();
        }

        private void DrawGraph()
        {

            int i, j, k;
            int w = 128;
            int h = 64;

            for (i = 0; i < 64; i++)
            {
                for (j = 0; j < 16; j++)
                {
                    data[i,j] = tab[i * 16 + j];
                }
            }
            Gui_Line(0, 0, 100, 50, 1);
            for (i = 0; i < 64; i++)
            {
                for (j = 0; j < 16; j++)
                {
                    for (k = 0; k < 8; k++)
                    {
                        if (((data[i, j] >> (7 - k)) & 0x01) == 1)
                        {
                            bmp.SetPixel(j * 8 + k, i, Color.Black);

                        }
                    }
                }
            }

            //显示图片
            graphics.DrawImage(bmp, new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height));
        }
        void MyDrawPoint(int x, int y, int color)
        {
            int x_byte = x / 8;
            int x_bit = x % 8;
            int y_row = y;
            if (color == 1)
            {
                byte temp = (byte)(7 - x_bit);
                data[y, x_byte] |= (byte)(1 << temp);
            }
        }
        //画水平线函数
        //参数:color=1,填充 1;color=0,填充 0;
        //x0,x1为起始和终点的水平坐标值,y 为垂直坐标值
        //**************************************************************
        void Gui_Hline(int x0, int x1, int y, int color)
        {
            //******数据调整*****
            int temp;
            if (x0 > x1)
            {
                temp = x0;
                x0 = x1; x1 = temp;
            }
            do//从左到右逐点显示
            {
                MyDrawPoint(x0, y, color);
                x0++;
            } while (x1 >= x0);
        }
        //画竖线函数
        void Gui_Rline(int x, int y0, int y1, int color)
        {
            int temp;
            if (y0 > y1)
            {
                temp = y0;
                y1 = y0;
                y0 = temp;
            }
            do
            {
                MyDrawPoint(x, y0, color);
                y0++;
            } while (y1 >= y0);
        }
        //任意两点画直线函数
        //参数:color=1,该线填充 1;color=0,该线填充 0;
        // x0:直线起点的x 坐标值,y0:直线起点的 y 坐标值
        // x1:直线终点的x 坐标值,y1:直线终点的 y 坐标值
        void Gui_Line(int x0, int y0, int x1, int y1, int color)
        {
            int dx;//直线 x 轴差值变量
            int dy;//直线 y 轴差值变量
            int dx_sym;//x 轴增长方向,为-1 时减值方向,为 1 是增值方向
            int dy_sym;//y 轴增长方向,为-1 时减值方向,为 1 时增值方向
            int dx_x2;//dx*2 值变量,用于加快运算速度
            int dy_x2;
            int di;//决策变量
            if (x0 == x1)//判断是否为垂直线
            {
                Gui_Rline(x0, y0, y1, color);//画垂线
                return;
            }
            if (y0 == y1)//判断是否是水平线
            {
                Gui_Hline(x0, x1, y0, color);
                return;
            }
            dx = x1 - x0; dy = y1 - y0;//求两点之间的差值
            //*****判断增长方向*****
            if (dx > 0) dx_sym = 1;
            else
            {
                if (dx < 0) dx_sym = -1;
                else { Gui_Rline(x0, y0, y1, color); return; }
            }
            if (dy > 0) dy_sym = 1;
            else
            {
                if (dy < 0) dy_sym = -1;
                else { Gui_Hline(x0, y0, y1, color); return; }
            }
            dx = dx_sym * dx;//计算 dx 的绝对值
            dy = dy_sym * dy;
            dx_x2 = dx * 2;//dx的 2 倍
            dy_x2 = dy * 2;
            /*使用Bresenham 法画直线*/
            if (dx >= dy)//对于 dx>=dy,则以x 轴为基准
            {
                di = dy_x2 - dx;
                while (x0 != x1)
                {
                    MyDrawPoint(x0, y0, color);
                    x0 += dx_sym;
                    if (di < 0) di += dy_x2;
                    else
                    {
                        di += dy_x2 - dx_x2;
                        y0 += dy_sym;
                    }
                }
                MyDrawPoint(x0, y0, color);//显示最后一个点
            }
            else //对于 dx<dy,则以 y 轴为基准
            {
                di = dx_x2 - dy;
                while (y0 != y1)
                {
                    MyDrawPoint(x0, y0, color);
                    y0 += dy_sym;
                    if (di < 0) di += dx_x2;
                    else
                    {
                        di += dx_x2 - dy_x2;
                        x0 = dx_sym;
                    }
                }
                MyDrawPoint(x0, y0, color);
            }
        }

    }

}
时间: 2024-10-09 00:22:06

项目中可能会用到12864液晶(或者其它分辨率的),用C#模拟了一下显示效果的相关文章

java项目中可能会使用到的jar包解释

一.Struts2 用的版本是struts2.3.1.1 一个简单的Struts项目所需的jar包有如下8个 1. struts2-core-2.3.1.1.jar: Struts2的核心类库. 2. xwork-core-2.3.1.1.jar: XWork核心类,XWork是一个标准的command模式实现,并且完全从web层剥离出来.WebWork被构建在Xwork上,而Struts2由Struts1和WebWork两个经典的MVC框架发展而来. 3. ognl-3.0.3.jar: 支持

项目中的有趣题目 -- 吃饺子问题

题目描述: 近日,项目中偶遇一个有趣的题目,感慨多多,备忘之.抽象出来,大致是: 桌上一共有100个饺子,其中有10个饺子包了硬币,问:连续吃到硬币的期望次数是多少次? 首先,定义一下这里的连续,如果我们将吃饺子的顺序抽象为一个100位的二进制数.并且吃到饺子表示为1,没吃到则为0,那么: 如果一次和第二次吃到,那么可表示为: 110.....,那么这里的连续吃到的次数为1. 如果数字为: ...1111.... ,那么这里连续的4个1表示3次连续,也就是说只要连续,就算1次. 期望次数,也就是

RPA实施过程中可能会遇到的14个坑

RPA的实施过程并非如我们所想的那样,总是一帆风顺.碰坑,在所难免.但也不必为此过于惊慌,因为,我们已经帮你把RPA实施之路上的坑找了出来.RPA实施过程中,将会遇到哪些坑? [不看全文大纲版]●组织层面:1-缺乏当地团队的时间承诺2-缺乏领导力支持3-缺乏IT支持4-缺乏分析/数据功能的支持5-缺乏人力资源支持6-责任划分不明确●流程层面:7-选择了对业务影响微不足道的流程8-选择了涉及更高层次认知任务的流程9-选择了一个子流程很简单但流程本身很复杂的流程10-选择了存在更好自定义解决方案的流

Vue 实际项目中你可能会遇见的坑

纸上得来终觉浅,绝知此事要躬行! Vue的文档和教程看的太多,小的demo做的多,也不如自己实际的进行一个完整项目的开发.只有做了才知道原来问题这么多,这里列举了一些你做demo教程可能不会遇见的坑. 一.项目的登录拦截及用户权限访问控制问题. 一个很常见的需求就是对未登录的用户进行路由拦截和用户的权限访问,如果你的项目之前是通过后台控制访问路由的,那么之前的后端现在可能需要在前端也需要控制了,由于我们用vue脚手架搭建的都是纯前端的路由访问,先看看我们的一般的项目路径: 你可能会注意到Vue的

Vue 实际项目中你可能会遇见问题

纸上得来终觉浅,绝知此事要躬行! Vue的文档和教程看的太多,小的demo做的多,也不如自己实际的进行一个完整项目的开发.只有做了才知道原来问题这么多,这里列举了一些你做demo教程可能不会遇见的坑. 一.项目的登录拦截及用户权限访问控制问题. 一个很常见的需求就是对未登录的用户进行路由拦截和用户的权限访问,如果你的项目之前是通过后台控制访问路由的,那么之前的后端现在可能需要在前端也需要控制了,由于我们用vue脚手架搭建的都是纯前端的路由访问,先看看我们的一般的项目路径: 你可能会注意到Vue的

Python+Selenium进行UI自动化测试项目中,常用的小技巧2:读取配置文件(configparser,.ini文件)

在自动化测试项目中,可能会碰到一些经常使用的但 很少变化的配置信息,下面就来介绍使用configparser来读取配置信息config.ini 读取的信息(config.ini)如下: [config]platformName=AndroidappPackage=com.sheinsideappActivity=.module.GuideActivitybaseUrl=http://0.0.0.0:4723/wd/hubfindElementTimes=10[cmd]openAppium=nod

160504项目中的error

在学习时,曾经遇到将同组的项目导入时出现红叉的情况.但是没有发现具体错误.开始以为是build path 的问题,于是在Libraries中将相关Jar包重新检查并添加了一遍,但并没有解决问题.后来仔细检查后才发现,是一个很简单的问题,之前都想复杂了.JDK版本不一样,把JDK7换掉重新装JDK8,再把相关配置好,红叉就解决大半. 作为菜鸟程序员,有时候一个很小的问题就能造成很大影响.而经验不足时,更不知道从何入手.为了能顺利编写项目,更为了能在编写项目时能解决出现的问题和错误而不是不知所措,就

项目中选择css框架的苦恼

优点 a) 提高开发效率. b) 规范名称定义,便于维护. c) 规范项目开发流程 d)css代码更清晰.简单.html代码更合理. e) 大规模项目中可以减少用户下载 弊端 a) 学习成本提高.你需要了解整个框架,需要阅读框架的文档. b)css框架对于一个小项目等页面来说很臃肿.框架中可能有大部分你用不到的代码. c)可能会无法帮助你的技术提高.太依赖框架,以至于很难排除bug.包括框架中本身就带的bug. d) 选择自己需要的框架与开发框架都很痛苦.写到后面发现越来越不灵活,越来越臃肿.

记一次项目中的css样式复用

本文同步至微信公众号:http://mp.weixin.qq.com/s?__biz=MzAxMzgwNDU3Mg==&mid=401616238&idx=1&sn=3c6e965283c632e9035875be43e6a305&scene=0#wechat_redirect 二维码: 一直觉得css是一个不被重视,或者说是重视不够的饭后甜点.因为它太“简单”,门槛低,不能彰显或提升广大闷骚程序猿的逼格...一直都想聊聊css相关的一些杂碎.正好借最近的一次项目实践来侃侃