Как получить снимок экрана формы

Какова Ваша причина того, чтобы иметь строку как первичный ключ?

я просто установил бы первичный ключ к автоматическому увеличивающему целочисленному полю и поместил бы индекс на строковое поле.

Тот путь, если Вы делаете поиски на таблице, они должны быть относительно быстрыми, и все Ваши соединения, и нормальные взлеты взгляда будут незатронуты в своей скорости.

можно также управлять суммой строкового поля, которое индексируется. Другими словами, можно сказать, "только индексируют первые 5 символов", если Вы думаете, что это будет достаточно. Или если Ваши данные могут быть относительно подобными, можно индексировать целое поле.

22
задан stevebot 26 February 2011 в 01:52
поделиться

6 ответов

Еще более простой ответ поддерживается .NET:

Control.DrawToBitmap .

25
ответ дан 29 November 2019 в 03:43
поделиться

Вот метод расширения, который вы можете использовать:

    #region Interop

    [DllImport("user32.dll")]
    static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr hdc, PRF_FLAGS drawingOptions);

    const uint WM_PRINT = 0x317;

    [Flags]
    enum PRF_FLAGS : uint
    {
        CHECKVISIBLE = 0x01,
        CHILDREN = 0x02,
        CLIENT = 0x04,
        ERASEBKGND = 0x08,
        NONCLIENT = 0x10,
        OWNED = 0x20
    }

    #endregion

    public static Image CaptureImage(this Control control)
    {
        Image img = new Bitmap(control.Width, control.Height);
        using (Graphics g = Graphics.FromImage(img))
        {
            SendMessage(
               control.Handle,
               WM_PRINT,
               g.GetHdc(),
               PRF_FLAGS.CLIENT | PRF_FLAGS.NONCLIENT | PRF_FLAGS.ERASEBKGND);
        }
        return img;
    }

Form наследуется от Control, поэтому вы можете использовать его и в форме.

2
ответ дан 29 November 2019 в 03:43
поделиться
         this.Opacity = 0;
        Rectangle bounds = Screen.GetBounds(Point.Empty);

        // create the bitmap to copy the screen shot to
        Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);

        // now copy the screen image to the graphics device from the bitmap
        using (Graphics gr = Graphics.FromImage(bitmap))
        {

            gr.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);          
        }
        this.Opacity = 100;

Теперь просто

        gr.Save(@"c\pic.jpg",ImageFormat.jpg);
1
ответ дан 29 November 2019 в 03:43
поделиться

Попробуйте это:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace ScreenshotCapturer
{
    public partial class Form1 : Form
    {
        private static Bitmap bmpScreenshot;
        private static Graphics gfxScreenshot;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnCapture_Click(object sender, EventArgs e)
        {
            // If the user has choosed a path where to save the screenshot
            if (saveScreenshot.ShowDialog() == DialogResult.OK)
            {
                // Hide the form so that it does not appear in the screenshot
                this.Hide();
                // Set the bitmap object to the size of the screen
                bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                // Create a graphics object from the bitmap
                gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                // Take the screenshot from the upper left corner to the right bottom corner
                gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                // Save the screenshot to the specified path that the user has chosen
                bmpScreenshot.Save(saveScreenshot.FileName, ImageFormat.Png);
                // Show the form again
                this.Show();
            }
        }
    }
}
6
ответ дан 29 November 2019 в 03:43
поделиться

Используйте метод Control.DrawToBitmap (). Например:

    private void timer1_Tick(object sender, EventArgs e) {
        var frm = Form.ActiveForm;
        using (var bmp = new Bitmap(frm.Width, frm.Height)) {
            frm.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
            bmp.Save(@"c:\temp\screenshot.png");
        }
    }
26
ответ дан 29 November 2019 в 03:43
поделиться

Это сохранит скриншот вашего активного окна на диск C:

.

SendKeys.Send("") используется для отправки нажатий клавиш на компьютер. В этом случае % используется для нажатия клавиш Alt и {PRTSC}, очевидно, для нажатия кнопки Print Screen на клавиатуре.

Надеюсь, это кому-нибудь поможет!

private void printScreenButton_Click(object sender, EventArgs e)
{
    SendKeys.Send("%{PRTSC}");
    Image img = Clipboard.GetImage();
    img.Save(@"C:\\testprintscreen.jpg");
}
1
ответ дан 29 November 2019 в 03:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: