Example #1
0
        public byte[] ReadAsByteArray()
        {
            SeekToPixelData();

            int size = (int)imageHeader.width * imageHeader.height * 3;

            byte[] buffer = new byte[size];

            int i = 0;

            for (int y = 0; y < Math.Abs(imageHeader.height); y++)
            {
                for (int x = 0; x < imageHeader.width; x++)
                {
                    BmpColor color = ReadPixel();

                    buffer[i * 3]     = color.r;
                    buffer[i * 3 + 1] = color.g;
                    buffer[i * 3 + 2] = color.b;

                    i++;
                }

                if (!zeroRemainder)
                {
                    stream.BaseStream.Seek(pad, SeekOrigin.Current);
                }
            }

            return(buffer);
        }
Example #2
0
        public BmpColor[] ReadScanLine()
        {
            BmpColor[] colors;

            colors = new BmpColor[imageHeader.width];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = ReadPixel();
            }

            if (!zeroRemainder)
            {
                stream.BaseStream.Seek(pad, SeekOrigin.Current);
            }

            return(colors);
        }
Example #3
0
        private void Btn_GetPos_Click(object sender, EventArgs e)
        {
            int width  = Screen.PrimaryScreen.Bounds.Width;
            int height = Screen.PrimaryScreen.Bounds.Height;

            if (!File.Exists(calibrationImagePath))
            {
                MessageBox.Show("未找到定位图文件calibration.bmp");
                MessageBox.Show("请参照文件夹中的calibrationSample.png来制作模拟器左上角的定位图,并保存在文件夹中,命名为calibration.bmp. \r\n注意需要保存为24位位图(*.bmp),模拟器分辨率为1280*720");
                return;
            }

            Bitmap   calibration = Image.FromFile(calibrationImagePath) as Bitmap;
            Bitmap   bitmap      = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            Graphics g           = Graphics.FromImage(bitmap);

            g.CopyFromScreen(0, 0, 0, 0, new Size(width, height));
            pictureBox1.Image = bitmap;

            List <Point> p = BmpColor.FindPic(0, 0, width, height, bitmap, calibration);

            if (p == null || p.Count == 0)
            {
                MessageBox.Show("桌面上找不到定位图");
                return;
            }

            gameX = p[0].X;
            gameY = p[0].Y;

            startXY = new Vector2Int(gameX, gameY);


            bitmap = new Bitmap(gameWidth, gameHeight, PixelFormat.Format24bppRgb);
            g      = Graphics.FromImage(bitmap);
            g.CopyFromScreen(gameX, gameY, 0, 0, new Size(gameWidth, gameHeight));
            pictureBox1.Image = bitmap;

            btn_GetPos.Text = "已定位";
        }