如何使用WPF VB中的滑块控件将亮度设置为图像 [英] HOW to set brightness to image using slider control in WPF VB
本文介绍了如何使用WPF VB中的滑块控件将亮度设置为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助
我在使用滑块控制的WPF中遇到图像亮度问题。
我试图将值传递给Brightness函数,它给出了一个错误
对象引用没有设置为对象的实例
我尝试过:
please help
I am stuck on image brightness problem in WPF using slider control.
I tried to pass values to Brightness function, it gives an error
"object reference not set to the instance of object"
What I have tried:
Public Shared Function Brightness(ByVal image As Bitmap, ByVal SliderValue As Integer) As Bitmap
'DrawImage(image, GetBrightnessMatrix(percent))
Dim brtR As Single = CSng(SliderValue / 100)
Dim brtG As Single = CSng(SliderValue / 100)
Dim brtB As Single = CSng(SliderValue / 100)
Dim image_attr As New ImageAttributes
Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
{ _
New Single() {brtR, 0.0, 0.0, 0.0, 0.0}, _
New Single() {0.0, brtG, 0.0, 0.0, 0.0}, _
New Single() {0.0, 0.0, brtB, 0.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
New Single() {0.0, 0.0, 0.0, 0.0, 1.0}})
Dim rect As Rectangle = _
Rectangle.Round(image.GetBounds(GraphicsUnit.Pixel))
Dim wid As Integer = image.Width
Dim hgt As Integer = image.Height
Dim img As New Bitmap(wid, hgt)
Dim gr As Graphics = Graphics.FromImage(img)
image_attr.SetColorMatrix(cm)
gr.DrawImage(image, rect, 0, 0, wid, _
hgt, GraphicsUnit.Pixel, image_attr)
Return img
End Function
Private Sub SliderBrightness_ValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Double)) Handles SliderBrightness.ValueChanged
If image1.Source IsNot Nothing Then
Dim i As Integer
i = SliderBrightness.Value
StackPanelImage.Source = ToBitmapImage(Brightness(bitmapimage, i))
End If
End Sub
推荐答案
看看这个答案: c# - 如何使用滑块调整图像的亮度和对比度? - 堆栈溢出 [ ^ ]
Check out this answer: c# - How to adjust Brightness and Contrast of an image using a slider? - Stack Overflow[^]
这篇关于如何使用WPF VB中的滑块控件将亮度设置为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文