Exemple #1
0
        //pictureBoxCenter載入影像停留時間
        private void Picture_timer_Tick(object sender, EventArgs e)
        {
            pictureBoxCenter.Visible = false;
            Invalidate();

            Picture_timer.Stop();

            ani_count = 0;           //動畫計數器
            pictureBoxCenter.Visible = true;
            Animation_timer.Start(); //啟動動畫
        }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //Logo位置處理
            Logo              = Image.FromFile(logo);
            logo_pic.Image    = Logo;
            logo_pic.SizeMode = PictureBoxSizeMode.AutoSize;
            logo_pic.Location = new Point(b_size, (ry - logo_pic.Size.Height) - b_size);

            /* //開始圖片位置處理
             * startPicture = Image.FromFile(startpic);
             * start_pic.Image = startPicture;
             * start_pic.SizeMode = PictureBoxSizeMode.Zoom;
             * start_pic.Location = new Point(b_size + (logo_pic.Size.Width + b_size ), (ry - start_pic.Size.Height) - b_size);
             * startPicture.RotateFlip(RotateFlipType.Rotate270FlipNone); //旋轉圖片*/


            //初始圖片置入處理
            for (int p = 0; p < baseImage.Length; p++)
            {
                photo = Image.FromFile(@"baseImage\" + baseImage[p]); //依照路徑取出原始圖檔
                photo.RotateFlip(RotateFlipType.Rotate270FlipNone);   //旋轉圖片
                photos[p] = photo;                                    //圖片存放陣列
            }

            //倒數圖片置入處理
            for (int q = 0; q < count_time.Length; q++)
            {
                timePhoto = Image.FromFile(@"countImage\" + count_time[q]); //依照路徑取出原始圖檔
                //timePhoto.RotateFlip(RotateFlipType.Rotate270FlipNone); //旋轉圖片
                timePhotos[q] = timePhoto;                                  //圖片存放陣列
            }
            Countbox.Location = new Point(b_size + (logo_pic.Size.Width + b_size * 3), (ry - Countbox.Size.Height) - b_size);
            Countbox.SizeMode = PictureBoxSizeMode.Zoom;

            //計算分割格數
            cnt_x = rx / b_size; //計算X 軸格數
            cnt_y = ry / b_size; //計算Y 軸格數

            //左下圖片設定
            pictureBoxCenter.Visible  = false;                                                   //隱藏pictureBoxCenter
            pictureBoxCenter.Size     = new Size(b_size * scale, b_size * scale);                //計算pictureBoxCenter大小
            pictureBoxCenter.Location = new Point(rx - (b_size * scale), ry - (b_size * scale)); //計算pictureBoxCenter位置

            v_size = (b_size * scale) / (fps + fps / 12);                                        //動畫的size變化量

            camera = new Capture(0);                                                             //取得camera值
            faceNo = 0;                                                                          //定義人臉索引值

            Picture_timer.Stop();                                                                //Picture_timer停止
            Animation_timer.Stop();


            //迴圈新增格數排列
            int sy = ry, sx = 0; //(x,y) = (sx,sy)
            int drt = -1;        //初始判斷換行參數

            for (int i = 0; i < cnt_x; i++)
            {
                for (int j = 0; j < cnt_y; j++)
                {
                    //定義新增格子
                    PictureBox px = new PictureBox(); //重複新增PictureBox
                    px.Width  = b_size;               //設定PictureBox長寬(正方形)
                    px.Height = b_size;

                    //Y 軸由左至右依序遞減新增PictureBox
                    if (drt < 0)
                    {
                        sy = sy + drt * b_size;
                    }

                    px.Location = new Point(sx, sy);//設定新增格數的Location
                    px.Visible  = true;
                    Controls.Add(px);

                    int mIndex = rnd.Next(baseImage.Length); //設定亂數索引值
                    photo    = photos[mIndex];
                    px.Image = photo;                        //初始圖片放入px

                    //尋找哪一個為台灣內的格子
                    //運算台灣底圖的解析度
                    int pb_x = px.Location.X;
                    int pb_y = px.Location.Y;
                    pb_x = pb_x / b_size;
                    pb_y = (pb_y + b_size) / b_size;
                    //taiwan.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    Color tw_color = taiwan.GetPixel(pb_x, pb_y - 1);

                    Color sc = tw_color;

                    //半透明處理
                    matrix = new ColorMatrix(nArray);
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    Image    srcImage    = photo;
                    Bitmap   resultImage = new Bitmap(srcImage.Width, srcImage.Height);
                    Graphics g           = Graphics.FromImage(resultImage);
                    g.DrawImage(srcImage, new Rectangle(0, 0, srcImage.Width, srcImage.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, attributes);

                    int rgb_r = sc.R;
                    int rgb_g = sc.G;
                    int rgb_b = sc.B;

                    //判斷底圖為白色就是台灣內的格子,是否顯示為半透明
                    if (rgb_r == 255 && rgb_g == 255 && rgb_b == 255)
                    {
                        px.Image = photo;
                    }
                    else
                    {
                        px.Image = resultImage;
                    }

                    //Y 軸由右至左依序遞減新增PictureBox
                    if (drt > 0)
                    {
                        sy = sy + drt * b_size;
                    }

                    px.SizeMode = PictureBoxSizeMode.Zoom;
                    pic[faceNo] = px;//將faceNO放入picturebox陣列
                    faceNo++;
                }

                //跳行
                sx  = sx + b_size;
                drt = -1 * drt;
            }

            faceNo = 0;//初始定義為0
            string date_path = @"C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922\opencv\data\haarcascades\haarcascade_frontalface_default.xml";

            haar = new HaarCascade(date_path);//抓取人臉xml路徑
        }