我试图让我的屏幕截图图像显示在控制面板窗体中的图片框中。但形象没有被越过。将存储的对象实例传递给另一个表单
我已被告知,该问题可能将下面的代码行内铺设:
ScreenCapture capture = new ScreenCapture();
capture.CaptureImage(showCursor, curSize, curPosition, startPoint, Point.Empty, bounds, _screenPath, fi);
正如我创建一个新的屏幕截图,该数据没有得到移交到我的照片框。当我运行我的程序中的错误与以下行总是返回null来源:
Image img = (Image)bitmap;
if (OnUpdateStatus == null) return;
ProgressEventArgs args = new ProgressEventArgs(img);
OnUpdateStatus(this, args);
然后在我的控制面板的winform我想如下显示图像:
private ScreenCapture _screenCap;
public ControlPanel()
{
InitializeComponent();
_screenCap = new ScreenCapture();
_screenCap.OnUpdateStatus += _screen_CapOnUpdateStatus;
}
private void _screen_CapOnUpdateStatus(object sender, ProgressEventArgs e)
{
imagePreview.Image = e.CapturedImage;
}
的意见,我被给出如下:
You're looking at the value of OnUpdateStatus within the CaptureImage method, right? So it matters which instead of ScreenCapture you call the method on. I suspect you need to pass _screenCap to the constructor of Form1 (which would need to store it in a field) so that you could use the same instance when you call CaptureImage within Form1
我不知道如何实施给我的建议。在我的代码前两行,我只是想拿走我的抓屏类的新实例的创建和写入
ScreenCapture.CaptureImage(showCursor, curSize, curPosition, startPoint, Point.Empty, bounds, _screenPath, fi);
但这生成以下错误:
Error 1 An object reference is required for the non-static field, method, or property 'DotFlickScreenCapture.ScreenCapture.CaptureImage(bool, System.Drawing.Size, System.Drawing.Point, System.Drawing.Point, System.Drawing.Point, System.Drawing.Rectangle, string, string)'
因此,要摆脱这个错误我把方法被称为静态类,但这产生不同的错误一大堆我的代码尝试存储拍摄的图像:
Image img = (Image)bitmap;
if (OnUpdateStatus == null) return;
ProgressEventArgs args = new ProgressEventArgs(img);
OnUpdateStatus(this, args);
它声称塔我的OnUpdateStatus需要一个对象引用,并且使用THIS关键字在静态字段或环境中无效。
是否有人能够帮助我的图像显示在图像框中?