我正在尝试在主监视器上打印(显示在屏幕上)屏幕截图,我想我已经具备了实现该功能所需的所有必要变量,但是我不知道如何克服“ PaintEventArgs”的问题。我应该发送什么,该怎么办?
编辑:这是我想做的http://msdn.microsoft.com/en-us/library/8tda2c3c.aspx
static void Main(string[] args)
{
Rectangle rect = Screen.PrimaryScreen.Bounds;
int color = Screen.PrimaryScreen.BitsPerPixel;
PixelFormat pf;
pf = PixelFormat.Format32bppArgb;
Bitmap BM= new Bitmap(rect.Width, rect.Height, pf);
Graphics g = Graphics.FromImage(BM);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
Bitmap bitamp = new Bitmap(BM);
print (bmp,) // what now?
}
private static void print(Bitmap BM, PaintEventArgs e)
{
Graphics graphicsObj = e.Graphics; // or "Bitmap bitmap = new Bitmap("Grapes.jpg");"
graphicsObj.DrawImage(BM, 60 ,10); // or "e.Graphics.DrawImage(bitmap, 60, 10);"
graphicsObj.Dispose();
}
PS:这是我第一次使用该网站,请原谅我可能犯的任何愚蠢的错误
您需要在print(Bitmap, PaintEventArgs)
表单事件中调用Paint
。
尝试一下
private void Form1_Load(object sender, EventArgs e)
{
Paint += new PaintEventHandler(Form1_Paint); //Link the Paint event to Form1_Paint; you can do this within the designer too!
}
private void print(Bitmap BM, PaintEventArgs e)
{
Graphics graphicsObj = e.Graphics; //Get graphics from the event
graphicsObj.DrawImage(BM, 60, 10); // or "e.Graphics.DrawImage(bitmap, 60, 10);"
graphicsObj.Dispose();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = Screen.PrimaryScreen.Bounds;
int color = Screen.PrimaryScreen.BitsPerPixel;
PixelFormat pf;
pf = PixelFormat.Format32bppArgb;
Bitmap BM = new Bitmap(rect.Width, rect.Height, pf); //This is the Bitmap Image; you have not yet selected a file,
//Bitmap BM = new Bitmap(Image.FromFile(@"D:\Resources\International\Picrofo_Logo.png"), rect.Width, rect.Height);
Graphics g = Graphics.FromImage(BM);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, rect.Size);
Bitmap bitamp = new Bitmap(BM);
print(bitamp, e);
}
谢谢,希望对您有所帮助:)
使其变得简单。
Form
我有一个很好的解决方案,但是您需要计算您的东西的位置和大小。不幸的是,我还没有弄清楚如何在屏幕上绘制img。
Form form = new Form();
form.Text = "Image Viewer";
PictureBox pictureBox = new PictureBox();
pictureBox.Image = YourImage;
pictureBox.Dock = DockStyle.Fill;
form.Controls.Add(pictureBox);
Application.Run(form);
我加入了一个循环功能,以使您的“东西”不会消失,尽管不幸的是,我制作的小白点确实会闪烁,因为它会在屏幕刷新时消失。
从 //Draw Image
// location of you image
Bitmap img = Properties.Resources.myImage;
// set image
Image newImg = img;
// draw a image
e.Graphics.DrawImage(newImg, 180F, 18F, newImg.Width, newImg.Height);
找到了这个解决方案。