Example #1
0
        // Show item color
        // Handle also mouse out event here.
        private void Picture1_MouseMove(System.Object eventSender, System.Windows.Forms.MouseEventArgs eventArgs)
        {
            int  x = eventArgs.X;
            int  y = eventArgs.Y;
            bool mouseOver;

            // Ensure whether Bitmap is not empty
            if (_bitmap != null && !_bitmap.IsEmpty)
            {
                // See if the mouse is over
                mouseOver = (0 <= x) && (x <= Picture1.Width) && (0 <= y) && (y <= Picture1.Height);

                currentPalleteIndex = (y / 17) * 16 + x / 17;

                if (mouseOver && (currentPalleteIndex < _bitmap.Palette.Count))
                {
                    // TextColor.Text = "#" & Hex(_bitmap.Palette(currentPalleteIndex).ToInt32)

                    TextColor.Text = "#" + _bitmap.Palette[currentPalleteIndex].ToInt32().ToString("X");

                    Picture2.Refresh();
                    NativeMethods.SetCapture(Picture1.Handle.ToInt32());
                }
                else
                {
                    // Show rect with cross lines
                    currentPalleteIndex = -1;
                    Picture2.Refresh();
                    TextColor.Text = string.Empty;
                    NativeMethods.ReleaseCapture();
                    return;
                }
            }
        }
        /// <summary>
        /// according to mouse movie translate picture
        /// </summary>
        /// <param name="DisplayImg"></param>
        /// <param name="CurrentMousePos"></param>
        /// <param name="LastMousePos"></param>
        public void MovePicture(System.Drawing.Bitmap DisplayImg, System.Drawing.Point CurrentMousePos, System.Drawing.Point LastMousePos)
        {
            try
            {
                System.Drawing.Size LeftTopDelta = new System.Drawing.Size();
                LeftTopDelta.Width  = CurrentMousePos.X - LastMousePos.X;
                LeftTopDelta.Height = CurrentMousePos.Y - LastMousePos.Y;

                origLeftTop.X += LeftTopDelta.Width;
                origLeftTop.Y += LeftTopDelta.Height;

                System.Drawing.Bitmap    newBitmap = new System.Drawing.Bitmap(_pcbox.Width, _pcbox.Height);
                System.Drawing.Rectangle ZoomSize  = new System.Drawing.Rectangle(origLeftTop.X, origLeftTop.Y, DisplaySize.Width, DisplaySize.Height);
                System.Drawing.Graphics  g         = System.Drawing.Graphics.FromImage(newBitmap);
                g.DrawImage(DisplayImg, ZoomSize);

                _pcbox.Image = newBitmap;
                _pcbox.Refresh();
            }
            catch (SystemException ex)
            {
                System.Windows.Forms.MessageBox.Show("In PictureboxZoomAndPan.MovePicture: " + ex.ToString());
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("In PictureboxZoomAndPan.MovePicture: " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }
        /*
         *  list have the ID of pixels
         *  pring pixels itself
         *  construct points
         *  draw curve passing by them
         */
        public void draw_line(List <int> l, graph g, System.Windows.Forms.PictureBox pictureBox1)
        {
            assign(l);
            Point[] points = new Point[orginal_path.Count + l.Count];
            // draw main path
            int i = 0;

            for (; i < orginal_path.Count; i++)
            {
                int   tid  = orginal_path[i];
                pixel tmp1 = helper.un_flatten(tid, g.width);
                Point tmp2 = new Point(tmp1.y, tmp1.x);  // col , row
                points[i] = tmp2;
            }

            // draw tmp temporary path
            for (int j = 0; j < tmp_path.Count; j++)
            {
                int   tid  = tmp_path[j];
                pixel tmp1 = helper.un_flatten(tid, g.width);
                Point tmp2 = new Point(tmp1.y, tmp1.x); // col , row
                points[i++] = tmp2;
            }
            if (points.Length >= 2)  // draw the whole curve
            {
                pictureBox1.Refresh();
                MainForm.gr.DrawCurve(MainForm.p, points);
            }
        }
Example #4
0
        private void pctbxDisp_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            System.Drawing.Point CurrentPoint = new System.Drawing.Point(e.X, e.Y);

            try
            {
                if (IsDraggingImg(e, _DisplayImg))
                {
                    _pctbxZoomAndPan.MovePicture(_DisplayImg, CurrentPoint, StartPoint);
                    StartPoint.X = e.X;
                    StartPoint.Y = e.Y;
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Left && drawLine == true)
                {
                    // draw line
                    _DisplayImg = tempBmpWhenDrawing.Clone(new System.Drawing.Rectangle(0, 0, SrcImg.Width, SrcImg.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    System.Drawing.Pen      pen = new System.Drawing.Pen(System.Drawing.Color.Blue, 3);
                    System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(_DisplayImg);
                    g.DrawLine(pen, StartPoint.X, StartPoint.Y, e.X, e.Y);
                    _pctbxDisp.Image = _DisplayImg;
                    _pctbxDisp.Refresh();
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Left && drawCircle == true)
                {
                    // draw circle
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Left && drawRect == true)
                {
                    // draw rectangle
                }
                else
                {
                    System.Drawing.Point RealPosition = new System.Drawing.Point(0, 0);
                    _pctbxZoomAndPan.CoordinateAfterZoom(ref RealPosition, CurrentPoint);
                    _mouseStatue = "(x, y) = (" + RealPosition.X.ToString() + ", " + RealPosition.Y.ToString() + ")";
                    if (_DisplayImg != null && e.X > 0 && e.Y > 0 && RealPosition.X < _DisplayImg.Width && RealPosition.Y < _DisplayImg.Height)
                    {
                        _mouseStatue = _mouseStatue + " || Gray = " + BeGotGrayImg.GetPixel(RealPosition.X, RealPosition.Y).ToString();
                    }
                    else
                    {
                        _mouseStatue = _mouseStatue + " || Gray = ";
                    }

                    if (_tbMouseStatue != null)
                    {
                        _tbMouseStatue.Text = _mouseStatue;
                    }
                }
            }
            catch (SystemException ex)
            {
                System.Windows.Forms.MessageBox.Show("In pctbxDisp_MouseMove: " + ex.ToString());
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("In pctbxDisp_MouseMove: " + ex.ToString());
            }
        }
Example #5
0
 public void Refresh()
 {
     // Use this especially for debugging and whenever you want to see what you have drawn so far
     pictureBoxView.Refresh();
     if (points != null)
     {
         Pen pen = new Pen(Color.Blue, 1);
         for (int i = 0; i < points.Length; i++)
         {
             if (i > 0)
             {
                 this.g.DrawLine(pen, points[i - 1], points[i]);
             }
         }
         this.g.DrawLine(pen, points[points.Length - 1], points[0]);
     }
 }
Example #6
0
 //Conjunction
 public bool Conjunction(System.Windows.Forms.PictureBox d, System.Windows.Forms.PictureBox b)
 {
     try
     {
         //when is splited
         if (Splited)
         {
             //initiate...
             ConjuctedBegin = true;
             SplitedBegin   = false;
             RootConjuction = new Bitmap(RootWidth, RootHeight);
             index          = imgarray.Count;
             //for evey items of list
             //Parallel.For(0, index, i =>
             for (i = 0; i < index; i++)
             {
                 Object O = new Object();
                 lock (O)
                 {
                     //create graphics of main empty image
                     var graphics = Graphics.FromImage(RootConjuction);
                     //store index
                     int k = imgarrayindex[i][0];
                     int p = imgarrayindex[i][1];
                     //write picess on main image
                     graphics.DrawImage(imgarray[i], new Rectangle(k, p, PiceX, PiceY), new Rectangle(0, 0, RootWidth, RootHeight), GraphicsUnit.Pixel);
                     //Assign and prepair
                     d.BackgroundImage       = imgarray[i];
                     d.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                     d.Refresh();
                     d.Update();
                     b.BackgroundImage       = RootConjuction;
                     b.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                     b.Refresh();
                     b.Update();
                     graphics.Dispose();
                 }
             }//);
             //initiate
             Conjucted = true;
             Splited   = false;
             imgarray.Clear();
         }
         else//when is not ready return unsuccessfull
         {
             return(false);
         }
     }
     catch (Exception t)
     {
         //when there is an exeption return unsuccessfull
         return(false);
     }
     //return successfull
     return(true);
 }
Example #7
0
        public void Draw(System.Windows.Forms.PictureBox pb, Graphics DrawingArea, Pen pen, int y, int delay = 0)
        {
            List <int> x = GetXvalues();

            if (delay != 0)
            {
                for (int i = 0; i < x.Count; i += 2)
                {
                    DrawingArea.DrawLine(pen, x[i], y, x[i + 1], y);
                    pb.CancelAsync();
                    pb.Refresh();
                    System.Threading.Thread.Sleep(delay);
                }
            }
            else
            {
                for (int i = 0; i < x.Count; i += 2)
                {
                    DrawingArea.DrawLine(pen, x[i], y, x[i + 1], y);
                }
            }
        }
Example #8
0
        public void PlayCdg(string fileName, System.Windows.Forms.PictureBox canvas)
        {
            int frameCount = 0;

            stopPlay = false;
            cdgFile  = new CDGFile(fileName);
            var mp3FileName = fileName.Replace(Path.GetExtension(fileName), ".mp3");
            var cdgLength   = cdgFile.getTotalDuration();

            PlayMp3File(mp3FileName);
            var startTime      = DateTime.Now;
            var endTime        = startTime.AddMilliseconds(cdgLength);
            var msecsRemaining = cdgLength;

            while (msecsRemaining > 0)
            {
                if (stopPlay)
                {
                    break;
                }
                msecsRemaining = (long)endTime.Subtract(DateTime.Now).TotalMilliseconds;
                var pos = cdgLength - msecsRemaining;
                while (pausePlay)
                {
                    endTime = DateTime.Now.AddMilliseconds(msecsRemaining);
                    System.Windows.Forms.Application.DoEvents();
                }
                cdgFile.renderAtPosition(pos);
                ++frameCount;
                canvas.Image     = cdgFile.get_RGBImage(false);
                canvas.BackColor = ((System.Drawing.Bitmap)canvas.Image).GetPixel(1, 1);
                canvas.Refresh();
                System.Windows.Forms.Application.DoEvents();
            }
            StopCdgFile();
        }
Example #9
0
 public void Refresh()
 {
     // Use this especially for debugging and whenever you want to see what you have drawn so far
     pictureBoxView.Refresh();
 }
Example #10
0
 //Split image to each pixel
 public bool Splitation(System.Windows.Forms.PictureBox d)
 {
     try
     {
         //when is ready
         if (Root != null)
         {
             //initiate...
             SplitedBegin   = true;
             ConjuctedBegin = false;
             imgarray       = new List <Image>();
             index          = 0;
             //for every width
             //Parallel.For(0, Root.Width, i =>
             for (i = 0; i < Root.Width; i += PiceX)
             {
                 //for every height
                 //Parallel.For(0, Root.Height, j =>
                 for (j = 0; j < Root.Height; j += PiceY)
                 {
                     Object O = new Object();
                     lock (O)
                     {
                         //create a image of picex and picey to an image
                         imgarray.Add(new Bitmap(PiceX, PiceY));
                         //increase
                         index++;
                         //write pices to an empty image
                         var graphics = Graphics.FromImage(imgarray[imgarray.Count - 1]);
                         graphics.DrawImage(Root, new Rectangle(0, 0, PiceX, PiceY), new Rectangle(i, j, PiceX, PiceY), GraphicsUnit.Pixel);
                         graphics.Dispose();
                         //show image on main picture box
                         d.BackgroundImage       = imgarray[imgarray.Count - 1];
                         d.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                         d.Refresh();
                         d.Update();
                         //add index
                         int[] a = new int[2];
                         a[0] = i;
                         a[1] = j;
                         imgarrayindex.Add(a);
                     }
                 } //);
             }     //);
             //set
             Splited   = true;
             Conjucted = false;
         }
         else//when is not ready return unssuccessfull
         {
             return(false);
         }
     }
     catch (Exception t)
     {
         //when is exeption return unsuccessfull
         return(false);
     }
     //return successfull
     return(true);
 }
Example #11
0
 public static void DrawBmpOnGameBoard()
 {
     board.Refresh();
     board.BackgroundImage = Image.FromFile(@"chess graphics/board.png");
     board.Image           = graphicsBmpBuffer;
 }
Example #12
0
 private void TrackBarTextHue_ValueChanged(object sender, System.EventArgs e)
 {
     PictureBoxAfter.Refresh();
 }
Example #13
0
 public static void Unload(this System.Windows.Forms.PictureBox pb)
 {
     pb.Image         = null;
     pb.ImageLocation = string.Empty;
     pb.Refresh();
 }
Example #14
0
 private void RadioButton_CheckedChanged(System.Object sender, System.EventArgs e)
 {
     PictureBox1.Refresh();
 }