Click here to Skip to main content
15,894,825 members

image contrast in vb.net

Omkaara asked:

Open original thread
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
Tags: Visual Basic (Visual Basic 8 (2005)), Visual Studio (Visual Studio 2005), Image

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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