我試圖讓我的屏幕截圖圖像顯示在控制面板窗體中的圖片框中。但形象沒有被越過。將存儲的對象實例傳遞給另一個表單
我已被告知,該問題可能將下面的代碼行內鋪設:
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關鍵字在靜態字段或環境中無效。
是否有人能夠幫助我的圖像顯示在圖像框中?