Click here to Skip to main content
16,016,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB.NET
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
Posted
Updated 18-Aug-17 0:01am
v4
Comments
shubh2895 18-Aug-17 5:05am    
Please Help me..:(

1 solution

 
Share this answer
 
Comments
shubh2895 18-Aug-17 6:28am    
thank you so much... it helps me alot..... :)
sorry for the harassing....
Graeme_Grant 18-Aug-17 6:29am    
Google search works ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900