Why would you use
System.Drawing.Bitmap
image in WPF? Maybe, according to the title of your question, you really need "to display image in WPF"? But then it does not have to be
System.Drawing.Bitmap
. WPF has its own image types. Look at this class hierarchy:
http://msdn.microsoft.com/en-us/library/system.windows.media.imagesource%28v=vs.110%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource%28v=vs.110%29.aspx#inheritanceContinued[
^].
Sometimes really have
System.Drawing.Bitmap
and need to convert it to show in WPF, which makes sense in certain cases. But you are not doing that. From your function, you are trying to the instance of
System.Drawing.Bitmap
(
which is useless for using in WPF) and save it to file. Not clear why. (And this is the way to mislead the function users, to have some
side effect, saving a file in your case, instead of just returning a value.)
For interoperability between
System.Drawing
and WPF, please see:
http://msdn.microsoft.com/en-us/library/system.windows.interop.imaging%28v=vs.110%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.windows.interop.interopbitmap%28v=vs.110%29.aspx[
^].
I'm not discussing any detail on this topic, just because this is hardly what you are trying to do. You are trying to utilize some data,
colorData
. You absolutely don't need to write it in
System.Drawing.Bitmap
. You need to write it to some object which you could utilize in WPF, which is a very different thing.
First of all, I don't know how your data is organized. It's up to you to sort it out and use appropriate pixel representation. You can use the class
System.Windows.Media.Imaging.WriteableBitmap
.
Please read the documentation:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28v=vs.110%29.aspx[
^].
—SA