I found this code on how to apply a color filter to a Bitmap object in C#. The problem with it is it uses unsafe code to accomplish this. Is there a managed, safe way to do this same thing? I know I could use a library like AForge.NET or something similar, but I’m hoping there is a simple way to just apply a color filter. All I need is simple color replacement, replacing white pixels with yellow. Any suggestions?
Share
You could always use the safe GetPixel and SetPixel methods, but they are slow when used on many pixels, which is the reason you use unsafe method to use pointers to the bitmap’s memory.
Unsafe is the way to do it.
If your bitmap is very small and you don’t care about performance all that much, use the GetPixel and SetPixel methods.
Usage would be:
OR