Draw a Bitmap image on the screen

后端 未结 4 1715
渐次进展
渐次进展 2021-01-13 15:40

Im trying to print (show in screen ) a screenshot on my main monitor , I think I’ve got all the necessary variables to make that happen but I have no clue how to get past

4条回答
  •  醉话见心
    2021-01-13 16:10

    I have a very good solution, but you need to calculate the position and sizing for your stuff. Unfortunately, I have not figured out how to draw an img to screen yet.

    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Threading;
    
    namespace DIRECTDRAW
    {
        class Program
        {
            [DllImport("user32.dll")]
            static extern IntPtr GetDC(IntPtr hwnd);
    
            static void draw(Rectangle r, Brush b, IntPtr hwnd)
            {
                using (Graphics g = Graphics.FromHdc(hwnd))
                {
                    g.FillRectangle(b, r);
                }
            }
    
            static void Main(string[] args)
            {
                int w = 5;
                int h = 5;
    
                Point xy = new Point(960 - w, 540 - h);
                draw(new Rectangle(xy, new Size(w, h)), new SolidBrush(Color.White), GetDC(IntPtr.Zero));
                Thread.Sleep(1);
                Main(args);
            }
        }
    }
    
    

    I put in a loop function so that your "thing" doesn't disappear, and I made the wait part at 1 milisecond so that the dot doesn't flicker. Thankfully it's a console app so it won't freeze.

    Found this solution out from Draw Directly To Screen.

提交回复
热议问题