create image with brightness and contrast at same time (like MS Word)

61 views Asked by At

Trying to add selection of Brightness/Contrast like Microsoft Word has on its ribbon selection for an image. Tried the following code, but it seems off the match that appears in Word. Trying to learn new techniques, so my code may be incorrect? Would appreciate direction on proper routine.

Here is image from Word on the left. May be hard to see the the Word is not as bright as mine (on the right)

Image from Word Image from my Code

'create image -40 brightness and -40 contrast vb.net
        Dim bmp As New Bitmap(origPic) 'original image
        Dim cm As New ColorMatrix(New Single()() {
            New Single() {1, 0, 0, 0, 0},
            New Single() {0, 1, 0, 0, 0},
            New Single() {0, 0, 1, 0, 0},
            New Single() {0, 0, 0, 1, 0},
            New Single() {-40 / 255.0F, -40 / 255.0F, -40 / 255.0F, 0, 1}})

        Dim ia As New ImageAttributes()
        ia.SetColorMatrix(cm)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.DrawImage(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, ia)
        PicCropImage.Image = bmp 'current picture box
        PicCropImage.Invalidate()

        g.Dispose()
0

There are 0 answers