-1

Purpose of my Question: I am hoping to get some perspective that is not so easily gotten by reading Microsoft overviews, class and method descriptions. Hopefully those more experienced than I can point me in the right direction.

Background of my Question: I am hardware engineer that develops silicon devices to process the output of CMOS image sensors to create a final picture. I usually prototype and test my algorithms in C or C++ (Yes super old school I know) before committing to hardware. On my latest project I decided to use c# and WPF instead.

What I tried and am still stuck on: BUT I am finding that c# and WPF are not so image friendly. For example I can only find one class that lets me manipulate at the pixel level, or create a bitmap from an array - and at that a one dimensional array. Two dimensional arrays are classic and very intuitive for imaging work - would Microsoft really not have any pre-canned classes to convert from a 2D array to a bitmap??? I must be using the wrong classes (I have tried almost everything under System.Windows.Media.Imaging.BitmapSource ).

Where have I gone wrong? Thanks in advance

Leop
  • 11

2 Answers2

2

WPF is not an imaging library or intended for image-processing, it is a UI platform/framework. BitmapSource is intended for displaying raster data in a WPF context, not for manipulating bitmap data.

You have a few options:

  • System.Drawing - which is a .NET wrapper around GDI. You can access raw bitmap data using bitmap.LockBits and unsafe C# byte* and UInt32* pointers to manipulate the data.
    • GDI supported hardware acceleration of 2D drawing operations until Windows Vista. Windows 7 added some hardware acceleration back, but the majority of operations are still performed in software. Given that CPUs today are so fast this shouldn't be a problem in practice. If you really do need modern hardware-accelerated 2D drawing you should use Direct2D.
    • Note that System.Drawing is not available in .NET Core as it heavily tied to Windows' GDI.
  • AForge.NET - is an open-source image-processing, computer vision, and artificial-intelligence library, however it builds on-top of System.Drawing.
  • ImageProcessor - is actually two libraries: the first is a wrapper around System.Drawing which provides common consumer-application image-processing tasks, such as generating thumbnails - the other is a .NET Core-capable image processing library which implements required bitmap operations itself: ImageSharp.
Dai
  • 141,631
  • 28
  • 261
  • 374
  • Well I should be more clear. I don't need a library to make image manipulations, those are the algorithms I am supposed to be writing & given that I am designing for hardware the code is going to be totally different then what you would do for a PC application - so working with an image as an array is what I want to keep. – Leop Nov 29 '16 at 02:58
  • What I want to offload is stuff like "show the bitmap to the user" and ask the user to enter a value for noise that gets passed to the class emulating the sensor. I feel like WPF is great for that stuff. It's the getting array to be a bitmap and getting a bitmap to be an array (because I need a bitmap to make display easy in wpf) that's giving me trouble. – Leop Nov 29 '16 at 03:01
0

See my Q&A here

Creating a BitmapImage WPF

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);

IntPtr hBitmap = bitmap.GetHbitmap();
try
{
    imageSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap,
                                                        IntPtr.Zero,
                                                        Int32Rect.Empty,
                                                        System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
catch (Exception e) { }
finally
{
    DeleteObject(hBitmap);
}
Community
  • 1
  • 1
Eamonn McEvoy
  • 8,876
  • 14
  • 53
  • 83