Ejemplo n.º 1
0
        public void SetCanvas(PictureBoxObj pb)
        {
            lock (_canvasSync)
            {
                if (pb == null || pb.Image == null)
                {
                    return;
                }

                Width  = pb.Width;
                Height = pb.Height;

                _backPicture = pb;
                this.Controls.Add(_backPicture);
                _backPicture.SendToBack();
                _backPicture.Invalidate();


                _frontPicture = new PictureBoxObj(_backPicture.ClientID, _backPicture.UniqueID, PictureBoxStatus.Canvas);
                this.Controls.Add(_frontPicture);

                _frontPicture.Width  = pb.Width;
                _frontPicture.Height = pb.Width;
                _frontPicture.Image  = new Bitmap(Width, Height);
                _frontPicture.BringToFront();

                _editPBDrawObjects[0] = new DrawObjectList(0);
            }

            _isCleared = false;
            _needUpdateFrontPicture = true;
            AppLogger.Log("Picture loaded: width " + Width + ", height " + Height);
        }
Ejemplo n.º 2
0
 public void UpdateCanvas()
 {
     if (!_needUpdateFrontPicture || IsCleared)
     {
         return;
     }
     lock (_canvasSync)
     {
         using (Graphics gr = Graphics.FromImage(_frontPicture.Image))
         {
             gr.DrawImage(_backPicture.Image, new Rectangle(0, 0, _frontPicture.Width, _frontPicture.Height),
                          new Rectangle(0, 0, _backPicture.Width, _backPicture.Height), GraphicsUnit.Pixel);
             PictureBoxObj[] pbs = _drawObjects.GetValues();
             if (pbs != null)
             {
                 for (int i = 0; i < pbs.Length; i++)
                 {
                     if (pbs[i] == null || pbs[i].Image == null)
                     {
                         continue;
                     }
                     Rectangle rectFrom = new Rectangle(0, 0, pbs[i].Width, pbs[i].Height);
                     Rectangle rectTo   = new Rectangle(pbs[i].Location.X, pbs[i].Location.Y, pbs[i].Width, pbs[i].Height);
                     gr.DrawImage(pbs[i].Image, rectTo, rectFrom, GraphicsUnit.Pixel);
                 }
             }
         }
         _frontPicture.Invalidate();
         _needUpdateFrontPicture = false;
     }
 }
Ejemplo n.º 3
0
        public void ApplyPictureObj(long picID)
        {
            lock (_canvasSync)
            {
                PictureBoxObj pic;
                _drawObjects.TryGetValue(picID, out pic);
                if (pic == null || pic.Image == null)
                {
                    return;
                }
                Bitmap bm = new Bitmap(pic.Image);

                using (Graphics gr = Graphics.FromImage(_backPicture.Image)){
                    gr.DrawImage(bm, pic.Location);
                }
                _drawObjects.Remove(picID);

                _backPicture.Controls.Remove(pic);
                pic.Dispose();
                RemoveDrawObjectList(picID);
                _backPicture.Invalidate();
                _needUpdateFrontPicture = true;
            }
        }
Ejemplo n.º 4
0
        public void AddPictureObj(PictureBoxObj pic, Point location)
        {
            if (IsCleared || pic == null)
            {
                return;
            }
            lock (_canvasSync)
            {
                if (_drawObjects.ContainsKey(pic.UniqueID))
                {
                    return;
                }

                _backPicture.Controls.Add(pic);
                pic.Location = location;
                _drawObjects.Add(pic.UniqueID, pic);
                _editPBDrawObjects.Add(pic.UniqueID, new DrawObjectList(pic.UniqueID));

                pic.Invalidate();
            }
            AppLogger.Log("Created new pictureBox, location: " + location + " size: " + pic.Size);
        }