windows - C# WPF 请问怎么改变一个函数中的变量?
本文介绍了windows - C# WPF 请问怎么改变一个函数中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我是想设置一个按钮来控制光暗度,但是不知道 C# 怎么改变函数中的某个变量。
下面是获得画面每一帧的代码。
void timer_Tick(object sender, EventArgs e)
{
Image<Bgr, Byte> currentFrame = capture.QueryFrame();
if (currentFrame != null)
{
Image<Gray, Byte> grayFrame = currentFrame.Convert<Gray, Byte>();
var detectedFaces = grayFrame.DetectHaarCascade(haarCascade)[0];
foreach (var face in detectedFaces)
//下面这句是用于修改识别框的颜色
//currentFrame.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 3);
currentFrame.Draw(face.rect, new Bgr(255, 0, 0), 3);
image1.Source = ToBitmapSource(currentFrame);//currentFrame乘以一个数可以改变光暗度
}
}
这里是写按钮功能
private void Increase(object sender, RoutedEventArgs e)
{
...
}
请教大神们,我怎么才能在上面函数中改变 timer_Tick 中的 currentFrame ?谢啦,C# 以前我没有学过,但是懂点别的,现在在自学应用中。
解决方案
这是个很基础的问题
private double brightness = 0.3 ; // 定义的亮度
void timer_Tick(object sender, EventArgs e)
{
......
......
currentFrame *= brightness ;
......
}
private void Increase(object sender, RoutedEventArgs e)
{
...
brightness += 0.1;
...
}
另外,image1.Source = ToBitmapSource(currentFrame);这句还要确定是线程安全的才行
这篇关于windows - C# WPF 请问怎么改变一个函数中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文