public void DisplayPicture(Bitmap img, PictureBox picBox) { picBox.Invoke(new EventHandler(delegate { picBox.Image = img; })); }
public void Move(PictureBox picture, int dx, int dy, int Delay) { int x = picture.Location.X, y = picture.Location.Y; while (x != dx || y != dy) { // mre.WaitOne(); if (x < dx) { x += 2; } if (x > dx) { x -= 2; } if (y < dy) { y += 2; } if (y > dy) { y -= 2; } try { picture.BeginInvoke((Action)(() => picture.Location = new Point(x, y))); if (Delay != 0) { picture.Invoke((Action)(() => picture.Refresh())); Thread.Sleep(Delay); } } catch (Exception) { } } }
/// <summary> /// Load the current version details from the Internet /// Then check the version of the engine against it. /// </summary> private void BuscarVersion(object target) { try { mLastVersion = VersionData.GetLastVersion(); picNewVersion.Invoke(new SimpleHandler(MostrarVersion)); } catch {} }
public void setPicture(PictureBox box, Image pic) { if (box.InvokeRequired) { try { box.Invoke(new PictureBoxDelegate(setPicture), new Object[] { box, pic }); } catch { } } else box.Image = pic; }
public static void UpdateImage(PictureBox i_PictoreBox, Image i_Image) { if (i_PictoreBox.InvokeRequired) { i_PictoreBox.Invoke(new Action<PictureBox, Image>(UpdateImage), i_PictoreBox, i_Image); } else { i_PictoreBox.Image = i_Image; } }
private void MoveDog(PictureBox pcb) { while (!((pcb.Location.X) >= (pcbPistaCorrida.Width - pcb.Width))) { int distance = MyRandom.Next(4); Point p = pcb.Location; p.X += distance; pcb.Invoke(() => pcb.Location = p); pcbPistaCorrida.Invoke(() => pcbPistaCorrida.Refresh()); Thread.Sleep(30); } TheWinnerDog(pcb); }
/// <summary> ///显示图片到Picture控件中 /// </summary> /// <methodName>ShowPreviewBmp</methodName> /// <param name="pictureBox">PictureBox 控件</param> public static void ShowPreviewBmp(System.Windows.Forms.PictureBox pictureBox) { if (!mIsInitLaser) { MessageBox.Show("激光器没有初始化"); return; } int width = pictureBox.Size.Width; int height = pictureBox.Size.Height; pictureBox.Invoke((EventHandler)(delegate { //使用GetPrevBitmap2可以使图像显示出来 IntPtr ptr = LMC1_GETPREVBITMAP2(width, height); pictureBox.Image = Bitmap.FromHbitmap(ptr); DeleteObject(ptr); })); }
public static int[] UpdatePictureBox(System.Windows.Forms.PictureBox PictureBoxControl, Image Image2Show, bool NormalizeImage = false) { int[] retval = new int[2]; retval[0] = 0; retval[1] = 0; int[] nullretval = new int[2]; retval[0] = 0; retval[1] = 0; if (PictureBoxControl.InvokeRequired) { UpdatePictureBoxCallback d = UpdatePictureBox; PictureBoxControl.Invoke(d, new object[] { PictureBoxControl, Image2Show, NormalizeImage }); } else { if (Image2Show == null) { PictureBoxControl.Image = null; return(nullretval); } if (NormalizeImage) { int th_width = PictureBoxControl.Width; int th_height = (int)(Math.Round(((double)th_width / (double)Image2Show.Width) * (double)Image2Show.Height, 0)); if (th_height > PictureBoxControl.Height) { th_height = PictureBoxControl.Height; th_width = (int)Math.Round((double)th_height * (double)Image2Show.Width / (double)Image2Show.Height); } PictureBoxControl.Image = Image2Show.GetThumbnailImage(th_width, th_height, null, IntPtr.Zero); retval[0] = th_width; retval[1] = th_height; } else { PictureBoxControl.Image = Image2Show; retval[0] = Image2Show.Width; retval[1] = Image2Show.Height; } } return(retval); }
private void setImage(PictureBox pcx, Bitmap map) { if (pcx.InvokeRequired) { pcx.Invoke(new setImageHandler(setImage), pcx, map); } else { pcx.Image = map; } }
private void updatePictureBox(PictureBox pic, Image value) { // value = (Image)(new Bitmap(value, new Size(800,50))); if (pic.InvokeRequired) { pic.Invoke(new picDelegate(updatePictureBox), new object[] { pic, value }); } else { pic.BackgroundImage = value; } }
public static void SetPictureBoxImage(PictureBox control, Image image) { if (control.InvokeRequired) control.Invoke(new SetPictureBoxImageDelegate(SetPictureBoxImage), new object[] { control, image }); else control.Image = image; }
private void setPictureBox(PictureBox control, bool visible) { if (control.InvokeRequired) { control.Invoke(new MethodInvoker(delegate { control.Visible = visible; })); } else { control.Visible = visible; } }
private void UpdatePbOriginalImage(PictureBox pb, Image img) { if (pb.InvokeRequired) { // This is a worker thread so delegate the task. pb.Invoke(new UpdatePbOriginalImageDelegate(this.UpdatePbOriginalImage), pb, img); } else { // This is the UI thread so perform the task. pbOriginal.Image = img; } }
private void updatePictureBox(Bitmap x, PictureBox l) { if (l.InvokeRequired) { // this is worker thread updatePictureBoxDelegate del = new updatePictureBoxDelegate(updatePictureBox); l.Invoke(del, new object[] { x, l }); } else { // this is UI thread l.Image = x; } }
/// <summary> /// This method demonstrates a pattern for making thread-safe /// calls on a Windows Forms control. /// /// If the calling thread is different from the thread that /// created the UserControl object's, this method creates a /// SetLocationCallback and calls itself asynchronously using the /// Invoke method. /// /// If the calling thread is the same as the thread that created /// the UserControl object's, the Location property is set directly. /// </summary> /// <param name="obj">The UserControl object's</param> /// <param name="newLocation">Move object to this location</param> public void show(PictureBox obj, Point newLocation) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. try { #region Set Location in Safely if (obj.InvokeRequired) { SetLocationCallback d = new SetLocationCallback(show); obj.Invoke(d, new object[] { obj, newLocation }); } else { // if: // original location = newLocation = (50, 50) // obj.Size = (70, 70) // ---------------------------- // Virtual location in form // (15,15)._______ // |(50,50)| // 70| .---|---. Original location in form // | | | | // |___|___| | // | | // ._______. // <---> // 35 // // create virtual location from original location: obj.Location = new Point(newLocation.X - (obj.Size.Width / 2), newLocation.Y - (obj.Size.Height / 2)); } #endregion } catch { } }
// set Image private void SetImage(PictureBox pic, string text) { if (pic.InvokeRequired) { pic.Invoke(new MethodInvoker(delegate { SetImage(pic, text); })); return; } pic.Image = Image.FromFile(text); }
public void Render(Bitmap img, Dictionary<int, List<int>> xDic, int xLength, int yLength, PictureBox pictureBox1, PictureBox pictureBox2, string shapeName) { try { var g = default(Graphics); var g2 = default(Graphics); //var imageSq = new List<MosaicTile>(); var newImg = new Bitmap(xLength * tileSize.Width, yLength * tileSize.Height); var pb2Img = new Bitmap(xLength * tileSize.Width, yLength * tileSize.Height); //var saveImg = new Bitmap(colorMap.GetLength(0) * tileSize.Width, colorMap.GetLength(1) * tileSize.Height); //var file = Graphics.FromImage(saveImg); var rand = new Random(); pictureBox1.Invoke(new MethodInvoker(() => { pictureBox1.Image = newImg; pictureBox2.Image = pb2Img; g = Graphics.FromImage(pictureBox1.Image); g2 = Graphics.FromImage(pictureBox2.Image); })); var b = new SolidBrush(Color.Black); g.FillRectangle(b, 0, 0, img.Width, img.Height); g2.FillRectangle(b, 0, 0, img.Width, img.Height); //file.FillRectangle(b, 0, 0, img.Width, img.Height); Rectangle destRect, srcRect; foreach (var xItem in xDic) { foreach (var yItem in xItem.Value) { int x = xItem.Key; int y = yItem; string[] files = Directory.GetFiles(ConfigurationSettings.AppSettings["DownloadImagesFolderPath"]) .Where(file => !file.ToLower().Contains("processed")) .ToArray(); string path = string.Empty; if (files.Length > 0) { path = files[0]; } else { var processedList = Directory.GetFiles(ConfigurationSettings.AppSettings["DownloadImagesFolderPath"]) .Where(file => file.ToLower().Contains("processed")).ToArray(); path = processedList[rand.Next(processedList.Length)]; } using (Image source = Image.FromFile(path)) { //imageSq.Add(new MosaicTile() //{ // X = x, // Y = y, // Image = path //}); srcRect = new Rectangle(0, 0, source.Width, source.Height); for (int i = 1; i < 15; ) { pictureBox2.Invoke(new MethodInvoker(() => { pictureBox2.Image = PictureBoxZoom(source, new Size(i, i)); int xloc = ((x * tileSize.Width)); int yloc = ((y * tileSize.Width)); if (xloc < 0) xloc = 0; if (yloc < 0) yloc = 0; pictureBox2.Location = new Point(xloc, yloc); pictureBox2.Refresh(); })); Thread.Sleep(400 / i); i += i; } destRect = new Rectangle(x * tileSize.Width, y * tileSize.Height, tileSize.Width, tileSize.Height); g.DrawImage(source, destRect, srcRect, GraphicsUnit.Pixel); //file.DrawImage(source, destRect, srcRect, GraphicsUnit.Pixel); pictureBox1.Invoke(new MethodInvoker(() => { pictureBox1.Refresh(); })); } if (files.Length > 0) { //File.Delete(path); File.Move(path, Path.GetDirectoryName(path) + "\\processed_" + Path.GetFileName(path)); } } } pictureBox2.Invoke(new MethodInvoker(() => { pictureBox1.Image.Save(string.Format(ConfigurationSettings.AppSettings["SaveMosaicImagefolder"] + "\\{0}.jpg", Guid.NewGuid().ToString("N"))); pictureBox2.Size = new System.Drawing.Size(5, 5); pictureBox2.Location = new System.Drawing.Point(0, 0); })); //return new Mosaic() //{ // Image = saveImg, // Tiles = imageSq //}; } catch (Exception ex) { throw ex; } }
private void updatePictureBox(PictureBox pic, Image value) { if (pic.InvokeRequired) { pic.Invoke(new picDelegate(updatePictureBox), new object[] { pic, value }); } else { pic.BackgroundImage = value; } }
private void updatePictureBox(PictureBox p, ref System.Drawing.Bitmap bmp) { if (p.IsDisposed == false) { if (p.InvokeRequired) { try { p.Invoke(new updatePictureBoxCallback(updatePictureBox), p, bmp); } catch (Exception ex) { } } else { p.Image = bmp; p.Refresh(); } } }
//Load ban do public void reload(PictureBox pic) { pic.Invoke(new EventHandler(delegate { try { Database myDatabase = new Database(); Bitmap image = new Bitmap(path); gr.DrawImage(image, 0, 0); #if ACTOR_BAOCHAY XmlNodeList node = (myDatabase.xml_bc).GetElementsByTagName("node"); #else XmlNodeList node = (myDatabase.xml).GetElementsByTagName("node"); XmlNodeList val = (myDatabase.xml).GetElementsByTagName("val"); foreach (XmlNode valchild in val) { int id = Int32.Parse(valchild.Attributes["id"].Value); DrawVan(id); } #endif foreach (XmlNode nodechild in node) { string mac = nodechild.Attributes["mac"].Value; if (mac == "00" || mac[0] == 'B') { DrawActor(mac); } else { DrawSensor(mac); } } pic.Image = bit; } catch {} })); }
//Load ban do public void reload(PictureBox pic) { pic.Invoke(new EventHandler(delegate { try { Database myDatabase = new Database(); Bitmap image = new Bitmap(path); gr.DrawImage(image, 0, 0); XmlNodeList node = (myDatabase.xml).GetElementsByTagName("node"); foreach (XmlNode nodechild in node) { string mac = nodechild.Attributes["mac"].Value; if (mac == "00" || mac[0] == 'B') { DrawActor(mac); } else { DrawSensor(mac); } } XmlNodeList val = (myDatabase.xml).GetElementsByTagName("val"); foreach (XmlNode valchild in val) { int id = Int32.Parse(valchild.Attributes["id"].Value); DrawVan(id); } // pictureBox.Image = bit; //pictureBox.Refresh(); pic.Image = bit; } catch { //DisplayData("Khong the load anh", tb); } })); }
public static void SetPictureBoxImageLocation(PictureBox control, string imageurl) { if (control.InvokeRequired) control.Invoke(new SetPictureBoxImageLocationDelegate(SetPictureBoxImageLocation), new object[] { control, imageurl }); else control.ImageLocation = imageurl; }
/// <summary> /// Sets the image in a picturebox and invalidates the picture box /// This is just a helper function that takes care of /// cross-thread invokations that would result in .NET /// exceptions. /// </summary> /// <param name="box"></param> /// <param name="image"></param> public static void SetImage(PictureBox box, Image image) { if (box.InvokeRequired) { box.Invoke(new setImage(SetImage), box, image); } else { box.Image = image; box.Invalidate(); } }