Results 1 to 7 of 7

Thread: [RESOLVED] draw highlights over an image

Threaded View

  1. #7
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,388

    Re: [RESOLVED] draw highlights over an image

    the is no "in between" and lockbits is part of the managed space. its just that a 24bpp bitmap is effectively an array of bytes, one byte for red, one for green and one for blue and that for each pixel. lockbits/scan0 allows you to directly access the RGB value of each pixel with the performance of a normal array read/write operation. i have not checked but i am sure that fastpix is actually using lockbits/scan0, but it encapsulates this away from you which is fair enough.

    but now comes the clou. i realized that the correct way to do this is not accessing pixels but instead using a color transformation matrix when calling drawimage.
    try this out:
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim img As New Bitmap("c:\kill\test.jpg")
    
            Dim matrix As New Imaging.ColorMatrix(
                        New Single()() {New Single() {1, 0, 0, 0, 0},
                                        New Single() {0, 1, 0, 0, 0},
                                        New Single() {0, 0, 0, 0, 0},
                                        New Single() {0, 0, 0, 1, 0},
                                        New Single() {0, 0, 0, 0, 1}
                                       })
    
            Dim Attributes As New Imaging.ImageAttributes
            Attributes.SetColorMatrix(matrix)
    
            Using g As Graphics = PictureBox1.CreateGraphics
                g.DrawImage(img, New Rectangle(0, 0, PictureBox1.Width, PictureBox1.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, Attributes)
            End Using
        End Sub
    Last edited by digitalShaman; Feb 24th, 2017 at 11:06 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width