C# ';System.Drawing.Graphics.FromImage(System.Drawing.Image)和#x27;是一个';方法';但是像';类型';
所以,我今天刚刚开始C#,希望能创建一个屏幕截图程序。最初,我打算使用AIR来实现这一点,因为在web开发方面我知道的更多。尽管如此,我还是看了这个()。它显示了如何获得屏幕截图的基本知识 因此,我试图将我在视频中看到的内容复制到C#,但出现以下错误:C# ';System.Drawing.Graphics.FromImage(System.Drawing.Image)和#x27;是一个';方法';但是像';类型';,c#,graphics,bitmap,drawing,C#,Graphics,Bitmap,Drawing,所以,我今天刚刚开始C#,希望能创建一个屏幕截图程序。最初,我打算使用AIR来实现这一点,因为在web开发方面我知道的更多。尽管如此,我还是看了这个()。它显示了如何获得屏幕截图的基本知识 因此,我试图将我在视频中看到的内容复制到C#,但出现以下错误: 'System.Drawing.Graphics.FromImage(System.Drawing.Image)' is a 'method' but is used like a 'type' 这是我的密码: using System; us
'System.Drawing.Graphics.FromImage(System.Drawing.Image)' is a 'method' but is used like a 'type'
这是我的密码:
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);
}
}
}
我使用的是Microsoft Visual C#2010 Express
我试过用谷歌搜索错误,但似乎无法找到答案。这是问题所在:
Graphics g = new Graphics.FromImage(b);
错误消息告诉您的是,您不需要在那里说new
,只要
Graphics g = Graphics.FromImage(b);
FromImage
功能已经将为您创建一个新图形对象。这是问题所在:
Graphics g = new Graphics.FromImage(b);
错误消息告诉您的是,您不需要在那里说new
,只要
Graphics g = Graphics.FromImage(b);
FromImage
函数已经为您创建了一个新图形对象。哇,我知道这将是显而易见的。谢谢哇,我就知道这会很明显。谢谢