Beispiel #1
0
        //private void backgroundWorkerCalcs_ProgressChanged(object sender, ProgressChangedEventArgs e)
        //{
        //    // Use this method to report progress to GUI
        //}

        /// <summary>
        /// Adds the Form's MainBmp and associated dispMandImage.MandRect.X, dispMandImage.MandRect.Right, dispMandImage.MandRect.Y and dispMandImage.MandRect.Bottom values to a stack implemented as ArrayList mainBmpImageList.
        /// </summary>
        private void pushBitmap()
        {
            // If adding an element back to the middle of the stack then clear all remaining elemments.
            if (imageListDisplayedElCount < mainBmpImageList.Count)
            {
                // Remove any trailing elements.
                mainBmpImageList.RemoveRange(imageListDisplayedElCount, mainBmpImageList.Count - imageListDisplayedElCount);
            }

            // If too many elements then remove one from the stack bottom and continue.
            if (mainBmpImageList.Count >= maxImages)
            {
                // Remove bottom element
                mainBmpImageList.RemoveAt(0);

                // Decrement count to adjust "top" element in stack for removed element.
                imageListDisplayedElCount--;
            }

            // Now create another element for the current bitmap at the end.
            MandImage i = new MandImage();

            i.CopyFrom(dispMandImage);
            mainBmpImageList.Add(i);

            // Update the count of the last element in the stack.
            imageListDisplayedElCount++;
        }
Beispiel #2
0
        // Copies a MandImage object AND its bitmap from the source to this object.
        public void CopyFrom(MandImage sourceMandelbrotImage)
        {
            if (ReferenceEquals(this, sourceMandelbrotImage))
            {
                // Don't bother copying because we're trying to copy the same object.
                return;
            }

            MandRect.CopyFrom(sourceMandelbrotImage.MandRect);

            // Copy bitmap.
            if (MainBmp.Size != sourceMandelbrotImage.MainBmp.Size)
            {
                throw (new Exception("Bitmap sizes do not match hence can't be copied in MandImage.CopyFrom()"));
            }
            else
            {
                using (Graphics g = Graphics.FromImage(MainBmp))
                {
                    g.DrawImage(sourceMandelbrotImage.MainBmp, 0, 0);
                }
            }
            m_bitmapCalculated = sourceMandelbrotImage.m_bitmapCalculated;
            formToUpdate       = sourceMandelbrotImage.formToUpdate;
            XInc = sourceMandelbrotImage.XInc;
            YInc = sourceMandelbrotImage.YInc;
            bitmapSectionCalcFinishedDelegate = sourceMandelbrotImage.bitmapSectionCalcFinishedDelegate;
            bitmapCalcFinishedDelegate        = sourceMandelbrotImage.bitmapCalcFinishedDelegate;
        }
Beispiel #3
0
        //private void timer1_Tick(object sender, EventArgs e)
        //{
        //    //Check whether threads are finished.
        //    ThreadInfo ti;
        //    for (int i = 0; i < tiArrayList.Count; i++)
        //    {
        //        ti = (ThreadInfo)tiArrayList[i];
        //        if (ti.threadFinished)
        //        {
        //            // Thread is finished so copy the bitmap back to the main bitmap and kill the thread info.

        //            Graphics mainBmpGraphics = Graphics.FromImage(MainBmp);
        //            //mainBmpGraphics.DrawImage(ti.bmp, new Rectangle(0, 0, MandImage.bitmapWidth, MandImage.bitmapHeight / 2), new Rectangle(0, 0, MandImage.bitmapWidth, MandImage.bitmapHeight / 2), GraphicsUnit.Pixel);
        //            MainBmp = ti.bmpSection;
        //            this.Invalidate();
        //            //pictureBox1.Image = MainBmp;
        //            //pictureBox1.Invalidate();
        //            UseWaitCursor = false;
        //            threadsActive = false;
        //            tiArrayList.RemoveAt(i);
        //            i--;
        //            mainBmpGraphics.Dispose();
        //        }
        //    }
        //}

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Turn of timer that is checking threads are finished.
            Boolean oldUseWaitCursor = UseWaitCursor;

            UseWaitCursor = true;

            //timer1.Enabled = false;

            // Instruct all threads to finish asap.
            MandImage.CancelThreads();

            //MessageBox.Show("Counted to " + c + "during thread exit wait.");
            UseWaitCursor = oldUseWaitCursor;
        }
Beispiel #4
0
        /// <summary>
        /// Update MainBmp and associated dispMandImage.MandRect.X, dispMandImage.MandRect.Right, dispMandImage.MandRect.Y and dispMandImage.MandRect.Bottom values from the "stack top" in ArrayList mainBmpImageList.
        /// Note that the count of elemetns to the current stack top is imageListDisplayedElCount.  Returns true for success.
        /// </summary>
        private bool popBitmap()
        {
            if (imageListDisplayedElCount <= 1)
            {
                // There is no element to pop off so indicate that pop failed. (we always leave the top element on the stack).
                return(false);
            }

            // Decrement count in line with count of new "top" element in stack.
            imageListDisplayedElCount--;

            // There is an element to pop so pop it.
            //Tuple<Bitmap, FloatType, FloatType, FloatType, FloatType> t = (Tuple<Bitmap, FloatType, FloatType, FloatType, FloatType>)mainBmpImageList[imageListDisplayedElCount-1];
            MandImage i = (MandImage)mainBmpImageList[imageListDisplayedElCount - 1];

            dispMandImage.CopyFrom(i);

            // Indicate that pop succeeded.
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Creates a video of a zooming in set of images starting with displayed image.
        /// </summary>
        private void CreateZoomVideo()
        {
            const int ZoomYInc = 5;

            // Create copy of start image as start point
            MandImage writeMandImage = new MandImage();
            dispMandImage

            // Create a zoom rectangle just a bit smaller than the current rectangle.
            Rectangle r = new Rectangle();

            r         = this.Bounds;
            r.Height -= (ZoomYInc + ZoomYInc);
            r.Y      += ZoomYInc;
            r.X      += (int)(ZoomYInc * MandImage.aspectRatio);
            r.Width   = (int)(r.Height * MandImage.aspectRatio);
            for (int i = 1; i <= 10; i++)
            {
                //this.panel1.Size = (Size)e.Location - (Size)dragMouseDownPoint;
                this.panel1.Height = Math.Min(e.X - dragMouseDownPoint.X, e.Y - dragMouseDownPoint.Y);
                this.panel1.Width  = (int)(this.panel1.Height * MandImage.aspectRatio);
            }
        }
Beispiel #6
0
        //private void SetPixel_Example(PaintEventArgs e)
        //{

        //    // Create a Bitmap object from a file.
        //    Bitmap myBitmap = new Bitmap("C:\\Users\\Peter\\Pictures\\HopperThumb.jpg");

        //    // Draw myBitmap to the screen.
        //    e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
        //        myBitmap.Height);

        //    // Set each pixel in myBitmap to black.
        //    for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
        //    {
        //        for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
        //        {
        //            myBitmap.SetPixel(Xcount, Ycount, Color.Black);
        //        }
        //    }

        //    // Draw myBitmap to the screen again.
        //    e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
        //        myBitmap.Width, myBitmap.Height);
        //}

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //return;

            //pictureBox1.Image = MainBmp;
            //pictureBox1.Invalidate();

            //e.ClipRectangle
            //e.Graphics.Clear(Color.Black);
            //e.Graphics.DrawImage(MainBmp, Math.Max((this.Width - MainBmp.Width) / 2, 0), Math.Max((this.Height - MainBmp.Height) / 2, 0), MainBmp.Width, MainBmp.Height);
            Rectangle src  = new Rectangle();
            Rectangle dest = new Rectangle();

            // If nothing to paint then exit.
            if (e.ClipRectangle.Width == 0 && e.ClipRectangle.Height == 0)
            {
                return;
            }

            if (e.ClipRectangle.X < mainBmpLocationInForm.X)
            {
                // Trying to paint a portion of the screen which requires a margin as the bmp is smaller than the form.
                src.X  = 0;
                dest.X = mainBmpLocationInForm.X;
                //src.Width = e.ClipRectangle.Width;
                dest.Width = Math.Min(e.ClipRectangle.Width - (mainBmpLocationInForm.X - e.ClipRectangle.X), MandImage.bitmapWidth);
                src.Width  = dest.Width;
            }
            else
            {
                // Trying to paint a portion of the screen which requires no margin as it's into a part of the bitmap.
                src.X      = e.ClipRectangle.X - mainBmpLocationInForm.X;
                src.Width  = Math.Min(e.ClipRectangle.Width, MandImage.bitmapWidth - src.X);
                dest.X     = e.ClipRectangle.X;
                dest.Width = src.Width;
            }

            if (e.ClipRectangle.Y < mainBmpLocationInForm.Y)
            {
                // Trying to paint a portion of the screen which requires a margin as the bmp is smaller than the form.
                src.Y  = 0;
                dest.Y = mainBmpLocationInForm.Y;
                //src.Height = e.ClipRectangle.Height;
                dest.Height = Math.Min(e.ClipRectangle.Height - (mainBmpLocationInForm.Y - e.ClipRectangle.Y), MandImage.bitmapHeight);
                src.Height  = dest.Height;
            }
            else
            {
                // Trying to paint a portion of the screen which requires no margin as it's into a part of the bitmap.
                src.Y       = e.ClipRectangle.Y - mainBmpLocationInForm.Y;
                src.Height  = Math.Min(e.ClipRectangle.Height, MandImage.bitmapHeight - src.Y);
                dest.Y      = e.ClipRectangle.Y;
                dest.Height = src.Height;
            }

            //src = e.ClipRectangle;
            //src.Offset(-mainBmpLocationInForm.X, -mainBmpLocationInForm.Y);
            e.Graphics.DrawImage(dispMandImage.MainBmp, dest, src, GraphicsUnit.Pixel);

            if (showZoomFrames)
            {
                // Draw zoom rectangles for remaining images in the stack.
                int       zoomX, zoomY, zoomWidth, zoomHeight;
                Pen       p = new Pen(Color.White);
                Rectangle zoomRect;
                FloatType zoomPixelXInc = MandImage.bitmapWidth / (dispMandImage.MandRect.Width);
                FloatType zoomPixelYInc = MandImage.bitmapHeight / (dispMandImage.MandRect.Height);

                for (int i = imageListDisplayedElCount; i < mainBmpImageList.Count; i++)
                {
                    // Find display rectange for this image
                    MandImage m = (MandImage)mainBmpImageList[i];

                    zoomWidth  = (int)(m.MandRect.Width * zoomPixelXInc);
                    zoomHeight = (int)(m.MandRect.Height * zoomPixelYInc);
                    zoomX      = mainBmpLocationInForm.X + (int)((m.MandRect.X - dispMandImage.MandRect.X) * zoomPixelXInc);
                    zoomY      = mainBmpLocationInForm.Y + (int)((m.MandRect.Y - dispMandImage.MandRect.Y) * zoomPixelYInc);

                    zoomRect = new Rectangle(zoomX, zoomY, zoomWidth, zoomHeight);
                    e.Graphics.DrawRectangle(p, zoomRect);
                }

                // Dispose of pen.
                p.Dispose();
            }
            //e.Graphics.DrawImage(MainBmp, Math.Max((this.Width - MainBmp.Width) / 2, 0), Math.Max((this.Height - MainBmp.Height) / 2, 0), 9, 9);

#if ShowPaintThreadProgress
            Debug.WriteLine("Form1_Paint() Thread ID " + Thread.CurrentThread.ManagedThreadId + " Paint invalidated Rect: " + e.ClipRectangle);
#endif

#if debugPaint == true
            // Check that what just got painted to the screen actually arrived on the screen by checking the pixel in the top left of the bit of the bitmap that
            // just got painted to see it's the same colour as the pixel that is now on the screen
            Color c1 = mainBmp.GetPixel(dest.X - mainBmpLocationInForm.X, dest.Y - mainBmpLocationInForm.Y);
            Color c2 = GetPixel(dest.X, dest.Y);

            if (c1 != c2)
            {
                Debugger.Break();
            }
#endif
        }
Beispiel #7
0
 private void BitmapCalcFinshed(MandImage updatedMandImage)
 {
     UseWaitCursor = false;
     Cursor        = Cursors.Default;
     pushBitmap();
 }