-1

I want to make the black line of the image into red or any other color.

enter image description here

Or can say want to generate the colourful QR code. Is this possible?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ios developer
  • 3,363
  • 3
  • 51
  • 111

1 Answers1

1

I have outlined the process here. You can stop at "That's the easy part!". That question asked for something far more complex, but the 'easy part' is all you will need because you have 2 colors.

Here's the meat of it:

  • Get a handle to the bitmap's pixel data
  • Learn how the buffer is structured so you could properly populate a 2D array of pixel values which have the form:

    typedef struct t_pixel { uint8_t r, g, b, a; } t_pixel;

Then create the color to locate:

const t_pixel ColorToLocate = { 0,0,0,255 }; // << black, opaque

And its substitution value:

const t_pixel SubstitutionColor = { 255,0,0,255 }; // << red, opaque

Iterate over the bitmap context's pixel buffer, creating t_pixels.

When you find a pixel which matches ColorToLocate, replace the source values with the values in SubstitutionColor.

Community
  • 1
  • 1
justin
  • 104,054
  • 14
  • 179
  • 226