我有一个项目,包含两个表单MainForm
和CrossCorrPlotForm
。在CrossCorrPlotForm
,我有两个charts
(CrossCorrExpChart
和CrossCorrRefChart
)我使用描述here和{{3}的代码启用了滚轮缩放功能}。
一切都运行得很好,直到我在chart
上添加了另一个histChart
(MainForm
),这是在从相机传入的每一帧(15-20 FPS)上更新的,使用BackgroundWorker
收集并绘制图像中的数据。现在,CrossCorrPlotChart
上的两个图表都不再可以缩放。
我认为这与实时更新图表有关,它将重点放在每次更新上。我尝试在代码中添加histChart.Focus = false
但无济于事,因为它看起来像#34; Control.Focused是只读的#34;。
有没有人知道如何让charts
再次缩放?
由于
编辑:以下是更新BackgroundWorker
的{{1}}代码:
chartHist
注意:
private void OnFrameReceived(Frame frame)
{
bgw1.RunWorkerAsync(frame);
}
private void bgw1_DoWork(object s, DoWorkEventArgs e)
{
Frame frame = (Frame)e.Argument;
myBitmap = null;
try
{
frame.Fill(ref myBitmap);
mycamera.QueueFrame(frame);
SaveBitmap = myBitmap.Clone(cloneRect, myBitmap.PixelFormat);
BitmapToPrint = myBitmap.Clone(cloneRect, myBitmap.PixelFormat);
}
catch {}
}
private void bgw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (this.InvokeRequired)
{
BeginInvoke((Action)(() => bgw1_RunWorkerCompleted(sender, e)));
}
else
{
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
DataFromBitmap DataFromBitmapHist = new DataFromBitmap(SaveBitmap.Clone(cloneRect, SaveBitmap.PixelFormat));
PixelColorCount = DataFromBitmapHist.ColorCountOutput();
}).Start();
chartHist.Titles["Title2"].Visible = false;
chartHist.Series["Pixel count"].Points.Clear();
//Plotting the pixel counter, to detect saturation
for (int i = 0; i < PixelColorCount.Length; i++)
{
chartHist.Series["Pixel count"].Points.AddXY(i, PixelColorCount[i]);
}
//If there are saturated pixels : toggle a title on chartHist to warn the user
if (PixelColorCount.Last() > 1)
{
chartHist.Titles["Title1"].Visible = false;
chartHist.Titles["Title2"].Visible = true;
}
else
{
chartHist.Titles["Title1"].Visible = true;
chartHist.Titles["Title2"].Visible = false;
}
}
}
是来自相机API的函数,它包含从相机收到OnFrameReceived
时触发的代码。Frame
将frame.Fill
对象中包含的图片放入Frame
。Bitmap
将mycamera.QueueFrame
对象发送回相机,以接收新图片。