How to create .NET Bitmap from BGR data
I am well aware of how to convert BGR to RBG "manually" using Bitmap.SetPixel
or unsafe code, but is there a .NET function which directly allows me to create a Bitmap from BGR data or to convert an BGR Bit开发者_运维问答map to an RGB Bitmap?
The scope of this question is, that I want to display image data in a user interface. But creating the Bitmap from my raw data and using PictureBox.Image
to display it, shows me red and blue interchanged.
I've worked on a couple commercial projects with a machine vision guy where we had to consume BGR bitmaps in .NET. Like you, we always did our own conversions. I've looked around multiple times in the past and aways came back with an answer that I needed to manage the conversion from BGR to RGB myself.
Emgu CV allows you to create an object directly from BGR data, and it can provide the image data back in Bitmap form ... synchronized so that a change to pixel data in one object affects the other object as well. Emgu CV has a pretty clean programming model, and since it is built on OpenCV, it would probably be pretty efficient as well. However, if you're not already needing to Open CV in your app, it would be severe overkill to take on Emgu CV as a dependency just for this one need.
精彩评论