Jos*_*ett 1 c# graphics drawing bitmap
所以,我今天刚开始使用C#,希望能够创建一个屏幕截图程序.最初,我正在考虑使用AIR来实现这一点,因为我对Web开发有很多了解.尽管如此,我还是看了这个教程(我正在尝试使用的代码).它显示了非常如何获得一个屏幕截图基础.
因此,我尝试将我在视频中看到的内容复制到C#,但是我收到以下错误:
'System.Drawing.Graphics.FromImage(System.Drawing.Image)' is a 'method' but is used like a 'type'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace ShareFastCommand {
class Program {
static void Main(string[] args) {
int left = 10, top = 10;
int right = 20, bottom = 20;
Bitmap b = new Bitmap(right - left, bottom - top);
Graphics g = new Graphics.FromImage(b);
Rectangle r = new Rectangle(left, top, right - left, bottom - top);
g.CopyFromScreen(left, top, 0, 0, r.Size);
b.Save("C://Users/Josh Foskett/Desktop/test.png", ImageFormat.Png);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Microsoft Visual C# 2010 Express.
我已经尝试过谷歌搜索错误等等,似乎无法弄明白.
这是问题所在:
Graphics g = new Graphics.FromImage(b);
Run Code Online (Sandbox Code Playgroud)
错误信息告诉你的是,你不需要在new那里说,只是
Graphics g = Graphics.FromImage(b);
Run Code Online (Sandbox Code Playgroud)
该FromImage函数已经new Graphics为您创建了一个对象.