GDI+: Set all pixels to given color while retaining existing alpha value

前端 未结 3 1738
萌比男神i
萌比男神i 2021-01-05 12:15

What is the best way to set the RGB components of every pixel in a System.Drawing.Bitmap to a single, solid color? If possible, I\'d like to avoid manually loop

3条回答
  •  自闭症患者
    2021-01-05 13:01

    Yes, use a ColorMatrix. It ought to look like this:

      0  0  0  0  0
      0  0  0  0  0
      0  0  0  0  0 
      0  0  0  1  0 
      R  G  B  0  1
    

    Where R, G and B are the scaled color values of the replacement color (divide by 255.0f)

提交回复
热议问题