Пример #1
0
            public void Do()
            {
                try
                {
                    var request = (HttpWebRequest)WebRequest.Create(url);

                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            using (var stream = response.GetResponseStream())
                            {
                                Image Image = new Bitmap(stream);// Bitmap.FromStream(stream);
                                edit.BeginInvoke(new Action(() =>
                                {
                                    edit.Image = Image;
                                }));
                            }
                        }
                    }
                }
                catch
                {
                    edit.BeginInvoke(new Action(() =>
                    {
                        edit.Image = null;
                    }));
                }
            }
Пример #2
0
 public void Animate()
 {
     pic.BeginInvoke(new Action(() => { pic.Image = sprHor[h, 0]; }));
     animThread = new Thread(AsyncAnim);
     animThread.Start();
     animThread.IsBackground = true;
 }
Пример #3
0
        private void LoadOriginAndTargetIconPic(PictureBox picture, JObject elementData, bool async = false)
        {
            var cachePath = BstManager.GetIconPicTmpPath(elementData);

            if (async)
            {
                MethodInvoker picUpdate = delegate
                {
                    if (File.Exists(cachePath))
                    {
                        picture.ImageLocation = cachePath;
                    }
                    else
                    {
                        picture.ImageLocation = BstManager.GetIconPicUrl(elementData);
                    }
                    picture.Load();
                };
                picture.BeginInvoke(picUpdate);
            }
            else
            {
                if (File.Exists(cachePath))
                {
                    picture.ImageLocation = cachePath;
                }
                else
                {
                    picture.ImageLocation = BstManager.GetIconPicUrl(elementData);
                }
                picture.Load();
            }
        }
Пример #4
0
 public static void CreatePoint(PictureBox pic, AGV agv, int raddix, Color corlo, int sw)
 {
     try
     {
         if (pic.InvokeRequired)
         {
             pic.BeginInvoke(new AddCreatPoint(CreatePoint), new object [] { pic, agv, raddix, corlo, sw });
         }
         else
         {
             SingleAgv itemagv = new SingleAgv(agv, sw);
             Graphics  g       = pic.CreateGraphics();
             g.FillEllipse(new SolidBrush(Color.Black), (float)ORIGIN.X - 3, (float)ORIGIN.Y - 3, 6, 6);
             foreach (double[] barr in itemagv.BarrierLocator)
             {
                 g.FillEllipse(new SolidBrush(corlo), (float)barr[1] - raddix, (float)barr[2] - raddix, raddix * 2, raddix * 2);
                 if ((int)barr[4] != 0)
                 {
                     g.DrawLine(Pens.Blue, new Point((int)agv.AgvLocation_X, (int)agv.AgvLocation_Y), new Point((int)barr [1], (int)barr [2]));
                 }
             }
             g.Dispose();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     GC.Collect();
     Application.DoEvents();
 }
Пример #5
0
        public static void PreviewImage(this PictureBox pic, Button Previewbtn, Button splitBtn, int NumX, int NumY)
        {
            if (NumY > 0 && NumX > 0 && Slicer.GetImagery != null && !isBusy)
            {
                Thread t = new Thread(() =>
                {
                    isBusy = true;
                    Previewbtn.BeginInvoke(new Action(() => Previewbtn.Enabled = false));
                    Previewbtn.BeginInvoke(new Action(() => Previewbtn.Text    = "Generating Map.."));
                    Task ts = new Task(() =>
                    {
                        Bitmap bmp = Slicer.GetImagery.Image.gridMap(NumX, NumY);
                        pic.BeginInvoke(new Action(() => pic.Image = bmp));

                        Previewbtn.BeginInvoke(new Action(() => Previewbtn.Text    = "Generate Preview Map"));
                        Previewbtn.BeginInvoke(new Action(() => Previewbtn.Enabled = true));
                        splitBtn.BeginInvoke(new Action(() => splitBtn.Enabled     = true));
                        isBusy = false;
                    });
                    ts.Start();
                });
                t.IsBackground = true;
                t.Start();
            }
        }
Пример #6
0
            private void CalculateClipMatrix()
            {
                mWorldScale = Matrix4.CreateScale(
                    new Vector3(mSize.Width / (mScale * mClip.Width), mSize.Height / (mScale * mClip.Height), 1f));

                //TODO - mSize.[W,H] may have to be reversed
                Matrix4 toClipScale = Matrix4.CreateScale(
                    new Vector3((mScale * mClip.Width) / mSize.Width, (mScale * mClip.Height) / mSize.Height, 1f));

                Vector3 topLeft         = new Vector3(mCrop.X, mCrop.Y, 0f);
                Matrix4 toClipTranslate = Matrix4.CreateTranslation(topLeft);

                mClipMatrix = Matrix4.Identity;
                //mClipMatrix *= mWorldMatrix;
                mClipMatrix *= toClipTranslate;
                mClipMatrix *= toClipScale;

                if (mDrawPanel.InvokeRequired)
                {
                    mDrawPanel.BeginInvoke(new Action(() => mDrawPanel.Invalidate()));
                }
                else
                {
                    mDrawPanel.Invalidate();
                }
            }
Пример #7
0
        //движение объекта как такового
        public void MovePatient(PictureBox picture, int finalX, int finalY, int Delay)
        {
            int x = picture.Location.X, y = picture.Location.Y;

            while (x != finalX || y != finalY)
            {
                _mre.WaitOne();
                if (x < finalX)
                {
                    x++;
                }
                if (x > finalX)
                {
                    x--;
                }
                if (y < finalY)
                {
                    y++;
                }
                if (y > finalY)
                {
                    y--;
                }
                picture.BeginInvoke((Action)(() => picture.Location = new Point(x, y)));
                Thread.Sleep(Delay);
            }
        }
Пример #8
0
 private void updateShotFace(FaceInfo f)
 {
     if (PicBoxShotFace != null)
     {
         Action d = () =>
         {
             if (f == null)
             {
                 PicBoxShotFace.Image = null;
             }
             else
             {
                 if (FaceAutoUpdateOn)
                 {
                     PicBoxShotFace.Image =
                         FaceRecgnize.DeepCopyBitmap((Bitmap)f.FaceShotBmp);//防止同时占用的异常,拷贝一份
                 }
                 else
                 {
                     PicBoxShotFace.Image = f.FaceShotBmp;
                 }
             }
         };
         PicBoxShotFace.BeginInvoke(d);
     }
 }
Пример #9
0
        private void WaitForImage()
        {
            ExposureStatus.BeginInvoke(new Action(() => ExposureStatus.Text = "Waiting For Image"));
            while (!AtikPInvoke.ArtemisImageReady(handle))
            {
                if (stopProcessing)
                {
                    stopProcessing = false;
                    return;
                }

                Thread.Sleep(100);
            }

            int x = 0, y = 0, w = 0, h = 0, binX = 0, binY = 0;

            AtikPInvoke.ArtemisGetImageData(handle, ref x, ref y,
                                            ref w, ref h,
                                            ref binX, ref binY);

            // Create memory to copy pixels into
            byte[] pix = new byte[w * h * 2];

            var intPtr = AtikPInvoke.ArtemisImageBuffer(handle);

            ExposureStatus.BeginInvoke(new Action(() => ExposureStatus.Text = "Converting"));

            Marshal.Copy(intPtr, pix, 0, w * h * 2);

            // create enough space for a 24 bit per pixel bitmap of the image
            byte[] bmpBytes = new byte[w * h * 3];
            for (int i = 0, j = 0; i < w * h; ++i, j += 2)
            {
                if (stopProcessing)
                {
                    stopProcessing = false;
                    return;
                }

                var val = pix[j];
                // we have a mono image so we place the same value into each bitmap byte
                bmpBytes[i]   = val;
                bmpBytes[++i] = val;
                bmpBytes[++i] = val;
            }

            var pic     = new Bitmap(w, h);
            var rect    = new Rectangle(0, 0, w, h);
            var picData = pic.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);

            Marshal.Copy(bmpBytes, 0, picData.Scan0, w * 3 * h);
            pic.UnlockBits(picData);

            PictureBox.BeginInvoke(new Action(() => PictureBox.Image        = pic));
            ExposureStatus.BeginInvoke(new Action(() => ExposureStatus.Text = "Idle"));

            StartExposureButton.BeginInvoke(new Action(() => StartExposureButton.Enabled = true));
            StopExposure.BeginInvoke(new Action(() => StopExposure.Enabled = false));
        }
Пример #10
0
        public void funkcija(object o)
        {
            PictureBox pb = (PictureBox)o;

            pb.BeginInvoke((MethodInvoker) delegate
            {
                pb.Image = op.GetRandomImage();
            });
        }
Пример #11
0
 /// <summary>
 /// 设置按钮的背景图
 /// </summary>
 private void SetBtnImage(PictureBox btn, Bitmap bitmap)
 {
     if (btn.InvokeRequired)
     {
         btn.BeginInvoke(new Action(delegate { btn.Image = bitmap; }));
     }
     else
     {
         btn.Image = bitmap;
     }
 }
Пример #12
0
 private void SetPicture(PictureBox pic, Image img)
 {
     if (pic.InvokeRequired)
     {
         pic.BeginInvoke(new MethodInvoker(delegate() { SetPicture(pic, img); }));
     }
     else
     {
         pic.Image = img;
     }
 }
Пример #13
0
 public static void InvokePictureBoxSetImage(PictureBox ctrl, Image picture)
 {
     if (ctrl.InvokeRequired)
     {
         ctrl.BeginInvoke(new Action <Image>(img => { ctrl.Image = img; }), picture);
     }
     else
     {
         ctrl.Image = picture;
     }
 }
Пример #14
0
 public static void SetImageAsync(this Form form, PictureBox control, string imageUrl)
 {
     Task.Factory.StartNew(() =>
     {
         var image = InitHelper.GetImage(imageUrl);
         control.BeginInvoke(new Action(() =>
         {
             control.Image = image;
         }));
     });
 }
 /// <summary>
 /// Sets the wait on load.
 /// </summary>
 /// <param name="pictureBox">The picture box.</param>
 /// <param name="value">if set to <c>true</c> [value].</param>
 public static void SetWaitOnLoad(this PictureBox pictureBox, bool value)
 {
     if (pictureBox.InvokeRequired)
     {
         pictureBox.BeginInvoke(new MethodInvoker(() => pictureBox.SetWaitOnLoad(value)));
     }
     else
     {
         pictureBox.WaitOnLoad = value;
         pictureBox.Refresh();
     }
 }
 /// <summary>
 /// Sets the image location.
 /// </summary>
 /// <param name="pictureBox">The picture box.</param>
 /// <param name="value">The value.</param>
 public static void SetImageLocation(this PictureBox pictureBox, string value)
 {
     if (pictureBox.InvokeRequired)
     {
         pictureBox.BeginInvoke(new MethodInvoker(() => pictureBox.SetImageLocation(value)));
     }
     else
     {
         pictureBox.ImageLocation = value;
         pictureBox.Refresh();
     }
 }
Пример #17
0
 public void DisplayOnPictureBox(PictureBox pb, Bitmap Bp)
 {
     if (pb.InvokeRequired)
     {
         DisplayOnPictureBoxcallback Db = new DisplayOnPictureBoxcallback(DisplayOnPictureBox);
         pb.BeginInvoke(Db, new object[] { pb, Bp });
     }
     else
     {
         pb.Image = Bp;
     }
 }
Пример #18
0
 public void WagStart()
 {
     if (isAlive)
     {
         WagStop();
         thread = new Thread(new ThreadStart(() =>
         {
             int num = 1;
             while (true)
             {
                 num = num == 0 ? 1 : 0;
                 pictureBox.BeginInvoke((MethodInvoker)(() =>
                 {
                     pictureBox.Image = birdImg[num];
                 }));
                 Thread.Sleep(200);
             }
         }));
         thread.Start();
     }
 }
 /// <summary>
 /// Sets the causes validation.
 /// </summary>
 /// <param name="pictureBox">The picture box.</param>
 /// <param name="value">if set to <c>true</c> [value].</param>
 public static void SetCausesValidation(this PictureBox pictureBox, bool value)
 {
     if (pictureBox.InvokeRequired)
     {
         pictureBox.BeginInvoke(new MethodInvoker(() => pictureBox.SetCausesValidation(value)));
     }
     else
     {
         pictureBox.CausesValidation = value;
         pictureBox.Refresh();
     }
 }
 /// <summary>
 /// Sets the error image.
 /// </summary>
 /// <param name="pictureBox">The picture box.</param>
 /// <param name="value">The value.</param>
 public static void SetErrorImage(this PictureBox pictureBox, Image value)
 {
     if (pictureBox.InvokeRequired)
     {
         pictureBox.BeginInvoke(new MethodInvoker(() => pictureBox.SetErrorImage(value)));
     }
     else
     {
         pictureBox.ErrorImage = value;
         pictureBox.Refresh();
     }
 }
 /// <summary>
 /// Sets the size mode.
 /// </summary>
 /// <param name="pictureBox">The picture box.</param>
 /// <param name="value">The value.</param>
 public static void SetSizeMode(this PictureBox pictureBox, PictureBoxSizeMode value)
 {
     if (pictureBox.InvokeRequired)
     {
         pictureBox.BeginInvoke(new MethodInvoker(() => pictureBox.SetSizeMode(value)));
     }
     else
     {
         pictureBox.SizeMode = value;
         pictureBox.Refresh();
     }
 }
 /// <summary>
 /// Sets the border style.
 /// </summary>
 /// <param name="pictureBox">The picture box.</param>
 /// <param name="value">The value.</param>
 public static void SetBorderStyle(this PictureBox pictureBox, BorderStyle value)
 {
     if (pictureBox.InvokeRequired)
     {
         pictureBox.BeginInvoke(new MethodInvoker(() => pictureBox.SetBorderStyle(value)));
     }
     else
     {
         pictureBox.BorderStyle = value;
         pictureBox.Refresh();
     }
 }
Пример #23
0
        private void DrawImage(InputData inputData, Bitmap originalImage, int width, int height)
        {
            var paddingV = Math.Max(inputData.ImagePadding, (int)Math.Round((inputData.ImageBoxHeight - height) / 2f));
            var paddingH = Math.Max(inputData.ImagePadding, (int)Math.Round((inputData.ImageBoxWidth - width) / 2f));

            var image = originalImage.Copy();

            outputImageBox.BeginInvoke((MethodInvoker)(() =>
            {
                outputImageBox.Image = image;
                outputImageBox.SetBounds(paddingH, paddingV, width, height);
            }));
        }
Пример #24
0
        public static void SetPCTValue(PictureBox ctrl, Bitmap value)
        {
            if (ctrl.InvokeRequired)
            {
                ctrl.BeginInvoke(new SetPCTHandler(SetPCTValue), ctrl, value);
                return;
            }

            try
            {
                ctrl.Image = value;
            }
            catch (Exception) { }
        }
Пример #25
0
        public static void SetPCTColor(PictureBox ctrl, Color value)
        {
            if (ctrl.InvokeRequired)
            {
                ctrl.BeginInvoke(new SetPCTColorHandler(SetPCTColor), ctrl, value);
                return;
            }

            try
            {
                ctrl.BackColor = value;
            }
            catch (Exception) { }
        }
Пример #26
0
 public void Do()
 {
     try
     {
         using (var client = new System.Net.WebClient())
         {
             using (var strream = client.OpenRead(url))
             {
                 Image Image = new Bitmap(strream);
                 edit.BeginInvoke(new Action(() =>
                 {
                     edit.Image = Image;
                 }));
             }
         }
     }
     catch
     {
         edit.BeginInvoke(new Action(() =>
         {
             edit.Image = null;
         }));
     }
 }
Пример #27
0
 private void ThreaSetPictureBoxBackColor(PictureBox PB, Bitmap BT)
 {
     if (PB.Image != BT)
     {
         if (PB.InvokeRequired)//等待异步
         {
             // 当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它
             Action <Bitmap> actionDelegate = (x) => { PB.Image = x; };
             PB.BeginInvoke(actionDelegate, BT);
         }
         else
         {
             PB.Image = BT;
         }
     }
 }
 public static void UpdateImage(PictureBox pic, Image img)
 {
     if (!pic.InvokeRequired)
     {
         lock (img)
         {
             pic.Image = new Bitmap(img);
         }
     }
     else
     {
         pic.BeginInvoke(
             new Action <Image>(delegate(Image img2) { UpdateImage(pic, img2); }),
             img);
     }
 }
Пример #29
0
 private void UpdateTrackingMonitor(Bitmap EyeImageBmp)
 {
     try
     {
         if (pictureBoxReference.InvokeRequired)
         {
             pictureBoxReference.BeginInvoke((DisplayEyeImage) delegate
             {
                 pictureBoxReference.Image = EyeImageBmp;
             });
         }
     }
     catch (System.Exception exc)
     {
         Console.WriteLine("Exception: " + exc.Message);
     }
 }
Пример #30
0
        private void button3_Click(object sender, EventArgs e) // add
        {
            stop = false;
            var picture = new PictureBox
            {
                Name     = "picture box",
                Location = new Point(173, 105),
                Image    = global::BounnceBall150719.Properties.Resources.pokaball1,
                SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom,
                TabIndex = 1,
                Size     = new System.Drawing.Size(136, 130),
                TabStop  = false,
            };

            picture.Click += new System.EventHandler(this.pictureBox1_Click);
            this.Controls.Add(picture);
            Task.Run(() =>
            {
                while (stop == false)
                {
                    Action b = () =>
                    {
                        { picture.Location = new Point(picture.Location.X + dx, picture.Location.Y + dy); }
                    };
                    picture.BeginInvoke(b);
                    if (picture.Location.X <= 0)
                    {
                        dx = 2;
                    }
                    if (picture.Location.Y <= 0)
                    {
                        dy = 2;
                    }
                    if (picture.Location.X >= panel1.Width - picture.Width)
                    {
                        dx = -2;
                    }
                    if (picture.Location.Y >= panel1.Height - picture.Height)
                    {
                        dy = -2;
                    }
                    Thread.Sleep(10);
                }
            });
        }