示例#1
0
        public static void ScreenCapture(string received, Form form)
        {
            EnsureControlDisplaysCorrectlyByAddingItToAHiddenForm(form);

            var b = new Bitmap(form.Width, form.Height, PixelFormat.Format32bppArgb);
            form.DrawToBitmap(b, new Rectangle(0, 0, form.Width, form.Height));
            b.Save(received, ImageFormat.Png);
        }
        /// <summary>
        /// Gets the form borderless snapshot.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns>Bitmap.</returns>
        public static Bitmap GetFormBorderlessSnapshot(this System.Windows.Forms.Form window)
        {
            using (var bmp = new Bitmap(window.Width, window.Height))
            {
                window.DrawToBitmap(bmp, new Rectangle(0, 0, window.Width, window.Height));

                System.Drawing.Point point = window.PointToScreen(System.Drawing.Point.Empty);

                Bitmap target = new Bitmap(window.ClientSize.Width, window.ClientSize.Height);
                using (Graphics g = Graphics.FromImage(target))
                {
                    var srcRect = new Rectangle(point.X - window.Location.X,
                                                point.Y - window.Location.Y, target.Width, target.Height);

                    g.DrawImage(bmp, 0, 0, srcRect, GraphicsUnit.Pixel);
                }

                return(target);
            }
        }
示例#3
0
        /// <summary>
        /// Draws the form to a bitmap.
        /// </summary>
        /// <param name="form">The form to draw.</param>
        /// <param name="clientArea">If only the client area (non-chrome area) should be drawn.</param>
        /// <returns>An image with the form drawn onto it.</returns>
        /// <remarks>Internally uses WM_PRINT to draw the form to an HDC.</remarks>
        public static Bitmap Draw(Form form, bool clientArea)
        {
            Bitmap bmp = new Bitmap(form.Width, form.Height);
            form.DrawToBitmap(bmp, new Rectangle(0, 0, form.Width, form.Height));

            if (clientArea)
            {
                Bitmap crop = new Bitmap(form.ClientRectangle.Width, form.ClientRectangle.Height);
                using (Graphics g = Graphics.FromImage(crop))
                {
                    Rectangle screenRectangle = form.RectangleToScreen(form.ClientRectangle);
                    int titleHeight = screenRectangle.Top - form.Top;
                    g.DrawImage(bmp, new Point((form.ClientRectangle.Width - form.Width) / 2, -titleHeight));
                }
                bmp.Dispose();
                bmp = crop;
            }
            return bmp;
        }
        private void DisplayComparisonPlot(MSSpectra spectrumX, MSSpectra spectrumY, double mzTolerance,
            string path = "comparison.png", string newTitle = "MS/MS Spectra")
        {
            var model = CreatePlot(spectrumX.Peaks, spectrumY.Peaks, mzTolerance);
            model.Title = newTitle;

            var plot = new PlotView();
            plot.Model = model;
            var form = new Form();
            form.Size = Screen.PrimaryScreen.WorkingArea.Size;
            plot.Dock = DockStyle.Fill;
            form.Controls.Add(plot);
            form.Show();

            IO.Utilities.SleepNow(3);

            using (var bitmap = new Bitmap(form.Width, form.Height))
            {
                form.DrawToBitmap(bitmap, form.DisplayRectangle);
                bitmap.Save(path);
            }
        }
示例#5
0
        public Bitmap PaintMap(Form f1, Graphics grap)
        {
            try
            {
                mapimage = new Bitmap(f1.Width, f1.Height);
                Rectangle frame = new Rectangle(new System.Drawing.Point(f1.Width, f1.Height), f1.Size);
                f1.DrawToBitmap(mapimage, frame);
                grap = Graphics.FromImage(mapimage);
                string[] lines = System.IO.File.ReadAllLines(_mapname.ToString());
                int Index_x;
                int Limit = _wide - 1;
                int Index_y;
                int Limit_Y = _height - 1;
                for (Index_x = 0; Index_x < Limit; Index_x++)
                {
                    for (Index_y = 0; Index_y < Limit_Y; Index_y++)
                    {
                        //paint(grap, new Point(Index_x, Index_y), 0);
                    }
                }

            }
            catch (Exception p)
            {
                Console.Write(p.Message);

            }
            return mapimage;
        }
        private void CaptureForm()
        {
            m_SourceForm.DrawToBitmap(bmpScreenCapture, new Rectangle(0, 0, m_SourceForm.Width, m_SourceForm.Height));

            //    CaptureScreen.
        }
示例#7
0
        //当前窗口上指定相对坐标,指定范围,转为点阵数据。
        public static byte[][] TAC_TurnAreaToPixData(Form fmImaNoScreen, int nPositionX, int nPositionY, int nAreaWidth, int nAreaHeight)
        {
            byte[][] tempDesData = new byte[nAreaHeight][];
            for (int i = 0; i < nAreaHeight; i++)
                tempDesData[i] = new byte[nAreaWidth];
            try
            {
                Bitmap bmpForm = new Bitmap(fmImaNoScreen.Width, fmImaNoScreen.Height);
                fmImaNoScreen.DrawToBitmap(bmpForm, new Rectangle(0, 0, bmpForm.Width, bmpForm.Height));
                Bitmap bmpDes = new Bitmap(nAreaWidth, nAreaHeight);
                Graphics grpForm = Graphics.FromImage(bmpDes);
                int Border = (fmImaNoScreen.Width - fmImaNoScreen.ClientSize.Width) / 2;
                Rectangle destRect = new Rectangle(nPositionX + Border,
                    nPositionY + fmImaNoScreen.Height - fmImaNoScreen.ClientSize.Height - Border,
                    nAreaWidth, nAreaHeight);
                Rectangle srcRect = new Rectangle(0, 0, nAreaWidth, nAreaHeight);
                grpForm.DrawImage(bmpForm, srcRect, destRect, GraphicsUnit.Pixel);

                System.Drawing.Imaging.BitmapData tempBitmapData = bmpDes.LockBits(srcRect, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                fmImaNoScreen.Enabled = false;
                unsafe
                {
                    byte* tempPixelData = (byte*)tempBitmapData.Scan0.ToPointer();
                    int jump = tempBitmapData.Stride - nAreaWidth * 3;
                    for (int i = 0; i < nAreaHeight; i++)
                    {
                        for (int j = 0; j < nAreaWidth; j++)
                        {
                            tempDesData[i][j] = TAC_IsBlack(*tempPixelData ^ 0xff, *(tempPixelData + 1) ^ 0xff, *(tempPixelData + 2) ^ 0xff, 1);
                            tempPixelData += 3;
                        }
                        tempPixelData += jump;
                    }
                }
                fmImaNoScreen.Enabled = true;
            }
            catch (Exception Mistake)
            {
                MessageBox.Show(Mistake.ToString());
                return null;
            }
            return tempDesData;
        }