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
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