示例#1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            lock (sendLock)
            {
                Task.Run(() =>
                {
                    byte x = 240;
                    byte y = 240;

                    List <byte> data = new List <byte>();

                    Screen.AddData(data, new List <byte>()
                    {
                        0x2a
                    }, true);
                    Screen.AddData(data, new List <byte>()
                    {
                        0, 0
                    });
                    Screen.AddData(data, new List <byte>()
                    {
                        0, (byte)(x - 1)
                    });
                    Screen.AddData(data, new List <byte>()
                    {
                        0x2b
                    }, true);
                    Screen.AddData(data, new List <byte>()
                    {
                        0, 0
                    });
                    Screen.AddData(data, new List <byte>()
                    {
                        0, (byte)(y - 1)
                    });
                    Screen.AddData(data, new List <byte>()
                    {
                        0x2c
                    }, true);

                    List <byte> sd = new List <byte>();
                    using (Bitmap img = new Bitmap(@"1.png"))
                    {
                        for (int i = 0; i < x; i++)
                        {
                            for (int j = 0; j < y; j++)
                            {
                                var color = img.GetPixel(y - i - 1, j);
                                //rrrr rggg gggb bbbb
                                var rgb565 = color.R / 8 * 2048 + color.G / 4 * 32 + color.B / 8;
                                sd.Add((byte)(rgb565 / 256));
                                sd.Add((byte)(rgb565 % 256));
                            }
                        }
                    }

                    //MessageBox.Show(sd.Count.ToString());
                    Screen.AddData(data, sd);

                    var r = hid.SendBytes(data.ToArray());
                });
            }
        }