0

I have a lot of pictures (about 10.000) and would need to paint with Pink on every pixel that is white.

I found multiple threads on getting the color of a pixel, but they require me to go over every pixel of every image and verify if it is white. On the other hand in python it can be done extremely quickly with numpy.

Is there a way to select only the white pixels quickly and paint over them in vb.net? maybe using gr.ExcludeClip() or something like that?

any help appreciated.

UPDATE with the current code

    Dim im As Image = Image.FromFile(imagepath & "\" & imagename)
    Dim palette = im.Palette
    Dim c As Color = Color.FromArgb(R, G, B)

    Dim mapWhite = New Imaging.ColorMap() With {
        .OldColor = Color.White,
        .NewColor = c
        }

    For i As Integer = 0 To palette.Entries.Length - 1

        If palette.Entries(i) = mapWhite.OldColor Then
            palette.Entries(i) = mapWhite.NewColor
        End If

    Next

    im.Palette = palette
sharkyenergy
  • 3,842
  • 10
  • 46
  • 97
  • 1
    See the `ImageRemapColors()` method shown here: [How to make colors in a Palette transparent when drawing 8bpp Bitmaps](https://stackoverflow.com/a/65498663/7444103) (it doesn't apply to just paletted images) -- Of course, you don't need to change the size of the Image, that's just part of that question. -- How much white is the *white* in your images? You probably need to define a threshold. – Jimi Jul 13 '22 at 11:59
  • @Jimi thank you, checking it out right now. i think that white should be white (255) but I have not checked all the images yet, could be that on some images it is less than that, but I would stick with 255 for this question.. Thank you! – sharkyenergy Jul 13 '22 at 13:26
  • @Jimi, sorry, took a long time to answer, i am working on it only now. I tried the code you linked, but in my Image the palette is empty. it has lenght 0.. `palette = myimage.Palette` any idea why? – sharkyenergy Jul 22 '22 at 14:04
  • @Jimi i updated the post above with my current code. the image file is a jpg loaded from the drive – sharkyenergy Jul 22 '22 at 14:10
  • Because the Image has no Palette? What is the `PixelFormat`? -- Note that the code I've linked also contains a method, `ImageRemapColors()`, that remaps the colors of an Image without a Palette. Just specify the what Color to replace with another. – Jimi Jul 22 '22 at 14:45

0 Answers0