Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
http://stackoverflow.com/questions/3115076/adjust-the-contrast-of-an-image-in-c-sharp-efficiently[^]



solution for above question is not working in vb 2005

i need solution in vb2005
below is vb2005 code

VB
Public Shared Function AdjustContrast(Image As Bitmap, Value As Single) As Bitmap
    Value = (100F + Value) / 100F
    Value *= Value
    Dim NewBitmap As Bitmap = DirectCast(Image.Clone(), Bitmap)
    Dim data As BitmapData = NewBitmap.LockBits(New Rectangle(0, 0, NewBitmap.Width, NewBitmap.Height), ImageLockMode.ReadWrite, NewBitmap.PixelFormat)

    For y As Integer = 0 To NewBitmap.Height - 1
        Dim row As Pointer(Of Byte) = CType(data.Scan0, Pointer(Of Byte)) + (y * data.Stride)
        Dim columnOffset As Integer = 0
        For x As Integer = 0 To NewBitmap.Width - 1
            Dim B As Byte = row(columnOffset)
            Dim G As Byte = row(columnOffset + 1)
            Dim R As Byte = row(columnOffset + 2)

            Dim Red As Single = R / 255F
            Dim Green As Single = G / 255F
            Dim Blue As Single = B / 255F
            Red = (((Red - 0.5F) * Value) + 0.5F) * 255F
            Green = (((Green - 0.5F) * Value) + 0.5F) * 255F
            Blue = (((Blue - 0.5F) * Value) + 0.5F) * 255F

            Dim iR As Integer = CInt(Red)
            iR = If(iR > 255, 255, iR)
            iR = If(iR < 0, 0, iR)
            Dim iG As Integer = CInt(Green)
            iG = If(iG > 255, 255, iG)
            iG = If(iG < 0, 0, iG)
            Dim iB As Integer = CInt(Blue)
            iB = If(iB > 255, 255, iB)
            iB = If(iB < 0, 0, iB)

            row(columnOffset) = CByte(iB)
            row(columnOffset + 1) = CByte(iG)
            row(columnOffset + 2) = CByte(iR)

            columnOffset += 4
        Next
    Next

    NewBitmap.UnlockBits(data)

    Return NewBitmap
End Function


pointer(of byte) gives error

pls help
Posted
Updated 1-Nov-12 20:53pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Nov-12 9:55am    
Not a question. "Not working" is not informative at all. What exactly happens? Did you try to ask the author of the answer?
--SA
ZurdoDev 2-Nov-12 16:38pm    
And there error is ...?
Omkaara 22-Nov-12 1:33am    
yes i did tried above code since im using vb2005 it does not support pointers
Dim row As Pointer(Of Byte) this line gives error
system.refecltion.pointer has no type parameters

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