public static object NormalizeImage(XIR.Image image) { SWM.PixelFormat format; int components; byte [] buffer; switch (image.Format) { case XIR.ImageFormat.Bgr24: format = SWM.PixelFormats.Bgr24; components = 3; break; case XIR.ImageFormat.Rgb24: format = SWM.PixelFormats.Rgb24; components = 3; break; case XIR.ImageFormat.Rgba32: format = SWM.PixelFormats.Bgra32; components = 4; break; case XIR.ImageFormat.Bgra32: format = SWM.PixelFormats.Bgra32; components = 4; break; default: return(null); } switch (image.Format) { case XIR.ImageFormat.Rgba32: buffer = new byte [image.Data.Length]; Array.Copy(image.Data, buffer, buffer.Length); for (int i = 0; i < image.Data.Length; i += components) { var b = buffer [i]; buffer [i] = buffer [i + 2]; buffer [i + 2] = b; } break; default: buffer = image.Data; break; } return(BitmapSource.Create( image.Width, image.Height, 96, 96, format, null, buffer, components * image.Width).RemoteRepresentation()); }
public static string Base64Data(this XIR.Image image) { return(Convert.ToBase64String(image.Data)); }