我试图在我的主显示器上打印(在屏幕上显示)截图,我想我已经有了所有必要的变量来实现这一点,但我不知道如何通过"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();
}
Run Code Online (Sandbox Code Playgroud)
PS:这是我第一次使用这个网站,所以请原谅我可能犯的任何错误的错误
最简单的方法是在PictureBox内部使用Windows窗体Form.
例如:
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);
Run Code Online (Sandbox Code Playgroud)
您需要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);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,
我希望你觉得这有帮助:)
| 归档时间: |
|
| 查看次数: |
27641 次 |
| 最近记录: |