private static BitmapSource MIplImageToBitmapSource(IntPtr ptr) { MIplImage m = (MIplImage)Marshal.PtrToStructure(ptr, typeof(MIplImage)); System.Windows.Media.PixelFormat pixelFormat; switch (m.nChannels) { case 1: pixelFormat = System.Windows.Media.PixelFormats.Gray8; break; case 2: pixelFormat = System.Windows.Media.PixelFormats.Gray8; break; case 3: pixelFormat = System.Windows.Media.PixelFormats.Bgr24; break; case 4: pixelFormat = System.Windows.Media.PixelFormats.Bgra32; break; default: pixelFormat = System.Windows.Media.PixelFormats.Bgr24; break; } return(BitmapSource.Create(m.width, m.height, 1, 1, pixelFormat, null, m.imageData, m.imageSize, m.widthStep)); }
public static BitmapSource ReadBitmapImage(string fileName) { //ShowImage(); //return null; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MIplImage))); //ptr = ReadImage(fileName); ptr = ReadImage(fileName); var n = Marshal.PtrToStructure(ptr, typeof(MIplImage)); MIplImage m = (MIplImage)n; //Bitmap img = new Bitmap(m.width, m.height, m.widthStep, System.Drawing.Imaging.PixelFormat.Format24bppRgb, m.imageData); BitmapSource bs = BitmapSource.Create(m.width, m.height, 96, 96, System.Windows.Media.PixelFormats.Rgb24, null, m.imageData, m.imageSize, m.widthStep); return(bs);// BitmapToBitmapImage(img); }
public static BitmapSource ReadBitmapImage1(string fileName) { System.Windows.Media.PixelFormat pixelFormat = System.Windows.Media.PixelFormats.Gray8; MIplImage m = ReadImage1(fileName); switch (m.nChannels) { case 3: pixelFormat = System.Windows.Media.PixelFormats.Rgb24; break; case 4: pixelFormat = System.Windows.Media.PixelFormats.Rgba64; break; } BitmapSource bs = BitmapSource.Create(m.width, m.height, 96, 96, pixelFormat, null, m.imageData, m.imageSize, m.widthStep); return(bs);// BitmapToBitmapImage(img); }
private static BitmapSource MIplImageToBitmapSource(MIplImage m) { System.Windows.Media.PixelFormat pixelFormat; switch (m.nChannels) { case 1: pixelFormat = System.Windows.Media.PixelFormats.Gray8; break; case 3: pixelFormat = System.Windows.Media.PixelFormats.Bgr24; break; case 4: pixelFormat = System.Windows.Media.PixelFormats.Bgra32; break; default: pixelFormat = System.Windows.Media.PixelFormats.Bgr24; break; } return(BitmapSource.Create(m.width, m.height, 1, 1, pixelFormat, null, m.imageData, m.imageSize, m.widthStep)); }