Exemple #1
0
        public static Bitmap mkDef()
        {
            Bitmap     def = new Bitmap(w, h);
            BitmapPlus bp  = new BitmapPlus(def);

            bp.BeginAcces();
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    bp.SetPixel(x, y, BackGround);
                }
            }
            for (int x = 0; x < w; x++)
            {
                bp.SetPixel(x, 100, Axiss);
            }
            for (int y = 75; y < 125; y++)
            {
                bp.SetPixel(100, y, Axiss);
                bp.SetPixel(200, y, Axiss);
                bp.SetPixel(300, y, Axiss);
            }
            bp.EndAccess();

            return(def);
        }
Exemple #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            GpStatusPlus stat       = NativeMethods.GdiplusStartup(out token, input, out output);
            string       bitmapPath = System.IO.Path.GetDirectoryName(GetType().Assembly.GetModules()[0].FullyQualifiedName);

            bitmapPath = System.IO.Path.Combine(bitmapPath, "test.jpg");
            StreamOnFile sf = new StreamOnFile(bitmapPath);

            bmp      = new BitmapPlus(sf);
            penWrite = new PenPlus(Color.Blue, 3);

            path = new GraphicsPath(FillMode.FillModeAlternate);
        }
Exemple #3
0
        static void mkPix()
        {
            pixelData = new byte[pict.Width, pict.Height, 3];

            BitmapPlus bp = new BitmapPlus(pict);

            bp.BeginAccess();

            for (int y = 0; y < pict.Height; y++)
            {
                for (int x = 0; x < pict.Width; x++)
                {
                    Color cc = bp.GetPixel(x, y);
                    pixelData[x, y, 0] = cc.R;
                    pixelData[x, y, 1] = cc.G;
                    pixelData[x, y, 2] = cc.B;
                }
            }

            bp.EndAccess();
        }
Exemple #4
0
        public static Bitmap testSine()
        {
            int        vmax = 99;
            Bitmap     res  = mkDef();
            BitmapPlus bp   = new BitmapPlus(res);

            bp.BeginAcces();
            for (int x = 0; x < w; x++)
            {
                int val = (int)(
                    (50.0 * Math.Sin(2.0 * Math.PI * (double)x / (double)w)) +
                    (50.0 * Math.Sin(8.0 * Math.PI * (double)x / (double)w)) +
                    (50.0 * Math.Sin(4.0 * Math.PI * (double)x / (double)w))
                    );

                if (-vmax < val && val < vmax)
                {
                    bp.SetPixel(x, val + 102, SubColor);
                    bp.SetPixel(x, val + 101, SubColor);
                    bp.SetPixel(x, val + 99, SubColor);
                    bp.SetPixel(x, val + 98, SubColor);
                    bp.SetPixel(x, val + 100, MainColor);
                }
                else if (val < -vmax)
                {
                    val = -vmax;
                    bp.SetPixel(x, val + 101, SubColor);
                    bp.SetPixel(x, val + 100, MainColor);
                }
                else
                {
                    val = vmax;
                    bp.SetPixel(x, val + 99, SubColor);
                    bp.SetPixel(x, val + 100, MainColor);
                }
            }
            bp.EndAccess();

            return(res);
        }
        public void DebugDumpGridToImage(string filename, System.Drawing.Imaging.ImageFormat format)
        {
#if DEBUG
            using (Bitmap gridBitmap = new Bitmap(ColCount, RowCount))
            {
                using (BitmapPlus bmpP = new BitmapPlus(gridBitmap, System.Drawing.Imaging.ImageLockMode.ReadWrite))
                {
                    Cell cell;
                    for (int row = 0; row < RowCount; row++)
                    {
                        for (int col = 0; col < ColCount; col++)
                        {
                            cell = GetAt(row, col);
                            bmpP.SetPixel(col, row, Color.FromArgb(cell.R, cell.G, cell.B));
                        }
                    }
                }

                gridBitmap.Save(filename, format);
            }
#endif
        }
Exemple #6
0
        public static Bitmap mkWave(
            float sin1, float sin2, float sin3, float sin4,
            float cos1, float cos2, float cos3, float cos4)
        {
            int        vmax = Int16.MaxValue;
            Bitmap     res  = mkDef();
            BitmapPlus bp   = new BitmapPlus(res);

            bp.BeginAcces();
            for (int x = 0; x < w; x++)
            {
                int val = (int)(
                    (vmax * sin1 * Math.Sin(2.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sin2 * Math.Sin(4.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sin3 * Math.Sin(6.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sin4 * Math.Sin(8.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * cos1 * Math.Cos(2.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * cos2 * Math.Cos(4.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * cos3 * Math.Cos(6.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * cos4 * Math.Cos(8.0 * Math.PI * (double)x / (double)w))
                    );

                if (val < Int16.MinValue)
                {
                    val = Int16.MinValue;
                }
                else if (Int16.MaxValue < val)
                {
                    val = vmax;
                }

                int plotval = (-val * 99 / Int16.MaxValue) + 100;

                bp.SetPixel(x, plotval, MainColor);
            }
            bp.EndAccess();

            return(res);
        }
Exemple #7
0
        public static Bitmap mkWave(SoundData sd)
        {
            int        vmax = Int16.MaxValue;
            Bitmap     res  = mkDef();
            BitmapPlus bp   = new BitmapPlus(res);

            bp.BeginAcces();
            for (int x = 0; x < w; x++)
            {
                int val = (int)(
                    (vmax * sd.sin1 * Math.Sin(2.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.sin2 * Math.Sin(4.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.sin3 * Math.Sin(6.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.sin4 * Math.Sin(8.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.sin8 * Math.Sin(16.0 * Math.PI * (double)x / (double)w)) +

                    (vmax * sd.cos1 * Math.Cos(2.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.cos2 * Math.Cos(4.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.cos3 * Math.Cos(6.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.cos4 * Math.Cos(8.0 * Math.PI * (double)x / (double)w)) +
                    (vmax * sd.cos8 * Math.Cos(16.0 * Math.PI * (double)x / (double)w))
                    );

                #region ks1
                if (x < 0.5 * w)
                {
                    val += (int)(vmax * sd.ksin1);
                }
                else
                {
                    val -= (int)(vmax * sd.ksin1);
                }
                #endregion

                #region ks2
                if (x < 0.25 * w)
                {
                    val += (int)(vmax * sd.ksin2);
                }
                else if (x < 0.5 * w)
                {
                    val -= (int)(vmax * sd.ksin2);
                }
                else if (x < 0.75 * w)
                {
                    val += (int)(vmax * sd.ksin2);
                }
                else
                {
                    val -= (int)(vmax * sd.ksin2);
                }
                #endregion

                #region ks3
                if (x < w / 6)
                {
                    val += (int)(vmax * sd.ksin3);
                }
                else if (x < w / 3)
                {
                    val -= (int)(vmax * sd.ksin3);
                }
                else if (x < w / 2)
                {
                    val += (int)(vmax * sd.ksin3);
                }
                else if (x < 2 * w / 3)
                {
                    val -= (int)(vmax * sd.ksin3);
                }
                else if (x < 5 * w / 6)
                {
                    val += (int)(vmax * sd.ksin3);
                }
                else
                {
                    val -= (int)(vmax * sd.ksin3);
                }
                #endregion

                #region ks4
                if (x < w * 0.125)
                {
                    val += (int)(vmax * sd.ksin4);
                }
                else if (x < w * 0.25)
                {
                    val -= (int)(vmax * sd.ksin4);
                }
                else if (x < w * 0.375)
                {
                    val += (int)(vmax * sd.ksin4);
                }
                else if (x < w * 0.5)
                {
                    val -= (int)(vmax * sd.ksin4);
                }
                else if (x < w * 0.625)
                {
                    val += (int)(vmax * sd.ksin4);
                }
                else if (x < w * 0.75)
                {
                    val -= (int)(vmax * sd.ksin4);
                }
                else if (x < w * 0.875)
                {
                    val += (int)(vmax * sd.ksin4);
                }
                else
                {
                    val -= (int)(vmax * sd.ksin4);
                }
                #endregion


                if (val < Int16.MinValue)
                {
                    val = Int16.MinValue;
                }
                else if (Int16.MaxValue < val)
                {
                    val = vmax;
                }

                int plotval = (-val * 99 / Int16.MaxValue) + 100;

                bp.SetPixel(x, plotval, MainColor);
            }
            bp.EndAccess();

            return(res);
        }
Exemple #8
0
        /// <summary>
        /// 画像の中心線上のRGBの合計値を計算し、該当する数字を返す
        /// </summary>
        /// <param name="img">画像</param>
        /// <returns></returns>
        public int RGBsum_to_number(BitmapPlus img_bit_p, int pos_x, int pos_y, int cell_width, int cell_height)
        {
            int R_sum = 0, G_sum = 0, B_sum = 0;

            for (int x = 0; x < cell_width; x++)
            {
                Color pixeldata = img_bit_p.GetPixel(cell_width * pos_x + x, cell_height * pos_y + cell_height / 2);
                R_sum += pixeldata.R;
                G_sum += pixeldata.G;
                B_sum += pixeldata.B;
            }

            if (pos_x == 0 && pos_y == 0)
            {
                //label1.Text = R_sum.ToString() + ", " + G_sum.ToString() + ", " + B_sum.ToString();
            }

            if (R_sum == 3008 && G_sum == 3008 && B_sum == 3008)
            {
                return(0);
            }
            else if (R_sum == 2432 && G_sum == 2432 && B_sum == 3197)
            {
                return(1);
            }
            else if (R_sum == 2048 && G_sum == 2688 && B_sum == 2048)
            {
                return(2);
            }
            else if (R_sum == 3386 && G_sum == 1856 && B_sum == 1856)
            {
                return(3);
            }
            else if (R_sum == 1088 && G_sum == 1088 && B_sum == 2368)
            {
                return(4);
            }
            else if (R_sum == 2368 && G_sum == 1088 && B_sum == 1088)
            {
                return(5);
            }
            else if (R_sum == 1088 && G_sum == 2368 && B_sum == 2368)
            {
                return(6);
            }
            else if (R_sum == 2432 && G_sum == 2432 && B_sum == 2432)
            {
                return(7);
            }
            else if (R_sum == 3070 && G_sum == 3070 && B_sum == 3070)
            {
                return(-1);
            }
            else if (R_sum == 2878 && G_sum == 2878 && B_sum == 2878)
            {
                return(-10);
            }
            else if (R_sum == 512 && G_sum == 512 && B_sum == 512)
            {
                restart_ = true;
            }
            else if (R_sum == 638 && G_sum == 128 && B_sum == 128)
            {
                restart_ = true;
            }
            else
            {
                label1.Text = "error";
                //is_running = false;
            }
            return(-1);
            // メモ
            // 埋: 3070, 3070, 3070
            // 旗: 2878, 2878, 2878
            // 0 : 3008, 3008, 3008
            // 1 : 2432, 2432, 3197
            // 2 : 2048, 2688, 2048
            // 3 : 3386, 1856, 1856
            // 4 : 1088, 1088, 2368
            // 5 : 2368, 1088, 1088
            // 6 : 1088, 2368, 2368
            // 7 : 2432, 2432, 2432
            // × :  512,  512,  512
            // ×2:  638,  128,  128
        }
Exemple #9
0
        private async void processing()
        {
            CancellationTokenSource cancelsource = new CancellationTokenSource();

            Point     mine2000_pos    = new Point();
            Rectangle mine2000_rect   = new Rectangle();
            Point     mine2000_offset = new Point(2, 34);

            mine2000_find(ref mine2000_pos, ref mine2000_rect);
            int counter_of_image = 0;

            var progress1 = new Progress <int>((hoge) =>
            {
                if (is_running)
                {
                    Bitmap img_bit = copy_from_screen(new Point(mine2000_pos.X + mine2000_offset.X, mine2000_pos.Y + mine2000_offset.Y), cell_width * map_width, cell_height * map_height);
                    img_bit.Save(counter_of_image.ToString() + ".jpg");
                    counter_of_image++;
                    BitmapPlus img_bit_p = new BitmapPlus(img_bit);
                    img_bit_p.BeginAccess();
                    for (int x = 0; x < map_width; x++)
                    {
                        for (int y = 0; y < map_height; y++)
                        {
                            map_field[x, y] = RGBsum_to_number(img_bit_p, x, y, cell_width, cell_height);
                        }
                    }
                    img_bit_p.EndAccess();
                    img_bit.Dispose();

                    // 操作をしたか
                    bool is_exist = false;

                    // 旗を立てる
                    for (int x = 0; x < map_width; x++)
                    {
                        for (int y = 0; y < map_height; y++)
                        {
                            if (map_field[x, y] > 0)
                            {
                                int count = 0;
                                for (int dx = -1; dx <= 1; dx++)
                                {
                                    for (int dy = -1; dy <= 1; dy++)
                                    {
                                        if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height)
                                        {
                                            if (map_field[x + dx, y + dy] < 0)
                                            {
                                                count++;
                                            }
                                        }
                                    }
                                }
                                if (count == map_field[x, y])
                                {
                                    for (int dx = -1; dx <= 1; dx++)
                                    {
                                        for (int dy = -1; dy <= 1; dy++)
                                        {
                                            if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height)
                                            {
                                                if (map_field[x + dx, y + dy] < 0)
                                                {
                                                    map_bomb[x + dx, y + dy] = true;
                                                }
                                            }
                                        }
                                    }
                                }

                                /*
                                 * else if (count < map_field[x, y]) // 操作ミス用(?)
                                 * {
                                 *  for (int dx = -1; dx <= 1; dx++)
                                 *  {
                                 *      for (int dy = -1; dy <= 1; dy++)
                                 *      {
                                 *          if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height)
                                 *          {
                                 *              if (map_field[x + dx, y + dy] < 0)
                                 *              {
                                 *                  map_bomb[x + dx, y + dy] = false;
                                 *              }
                                 *          }
                                 *      }
                                 *  }
                                 * }
                                 */
                            }
                        }
                    }
                    if (MouseButtons == MouseButtons.None)
                    {
                        Point mouse_pos = Cursor.Position;
                        for (int x = 0; x < map_width; x++)
                        {
                            for (int y = 0; y < map_height; y++)
                            {
                                if (map_bomb[x, y] && map_field[x, y] != -10 && !map_flag[x, y])
                                {
                                    Cursor.Position = new Point(mine2000_pos.X + mine2000_offset.X + cell_width * x, mine2000_pos.Y + mine2000_offset.Y + cell_height * y);
                                    mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
                                    mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
                                    map_flag[x, y] = true;

                                    is_exist = true;
                                }
                            }
                        }
                        Cursor.Position = mouse_pos;
                    }
                    // マスを拓く

                    if (MouseButtons == MouseButtons.None)
                    {
                        Point mouse_pos = Cursor.Position;

                        for (int x = 0; x < map_width; x++)
                        {
                            for (int y = 0; y < map_height; y++)
                            {
                                if (map_field[x, y] > 0)
                                {
                                    int count  = 0;
                                    bool valid = false;
                                    for (int dx = -1; dx <= 1; dx++)
                                    {
                                        for (int dy = -1; dy <= 1; dy++)
                                        {
                                            if (x + dx >= 0 && x + dx < map_width && y + dy >= 0 && y + dy < map_height)
                                            {
                                                if (map_field[x + dx, y + dy] == -10)
                                                {
                                                    count++;
                                                }
                                                else if (map_field[x + dx, y + dy] == -1)
                                                {
                                                    valid = true;
                                                }
                                            }
                                        }
                                    }
                                    if (count == map_field[x, y] && valid)
                                    {
                                        Cursor.Position = new Point(mine2000_pos.X + mine2000_offset.X + cell_width * x, mine2000_pos.Y + mine2000_offset.Y + cell_height * y);
                                        mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
                                        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                                        mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
                                        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                                        is_exist = true;
                                    }
                                }
                            }
                        }

                        Cursor.Position = mouse_pos;
                    }

                    if (!is_exist)
                    {
                        label1.Text = "Nothing";

                        Point mouse_pos = Cursor.Position;

                        for (int x = 0; x < map_width; x++)
                        {
                            for (int y = 0; y < map_height; y++)
                            {
                                if (map_field[x, y] == -1)
                                {
                                    Cursor.Position = new Point(mine2000_pos.X + mine2000_offset.X + cell_width * x, mine2000_pos.Y + mine2000_offset.Y + cell_height * y);
                                    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                                    is_exist = true;
                                    break;
                                }
                            }
                            if (is_exist)
                            {
                                break;
                            }
                        }

                        is_exist        = false;
                        Cursor.Position = mouse_pos;
                    }
                }
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                }
                pictureBox1.Image = copy_from_screen(new Point(mine2000_pos.X + mine2000_offset.X, mine2000_pos.Y + mine2000_offset.Y), cell_width * map_width, cell_height * map_height);

                if (!is_running)
                {
                    label1.Text = "stop";
                }
                if (restart_)
                {
                    Initializing();
                    restart_ = false;
                }
            });
            bool ret = await Span1(progress1, cancelsource.Token, process_span);
        }