public static void LoadFromTiff(SharpDX.WIC.ImagingFactory imagingFactory, UnmanagedImage image, string filename, int bytesPerPixel)
 {
     // TODO: this function is more generic; rewrite to handle different formats/bytesPerPixel
     var decoder = new SharpDX.WIC.BitmapDecoder(imagingFactory, filename, SharpDX.WIC.DecodeOptions.CacheOnLoad);
     var bitmapFrameDecode = decoder.GetFrame(0);
     bitmapFrameDecode.CopyPixels(image.Width * bytesPerPixel, image.DataIntPtr, image.Width * image.Height * bytesPerPixel);
     bitmapFrameDecode.Dispose();
     decoder.Dispose();
 }
 public static void SaveToTiff(SharpDX.WIC.ImagingFactory imagingFactory, UnmanagedImage image, string filename, Guid format, int bytesPerPixel)
 {
     var file = new System.IO.FileStream(filename, System.IO.FileMode.Create);
     var stream = new SharpDX.WIC.WICStream(imagingFactory, file);
     var encoder = new SharpDX.WIC.BitmapEncoder(imagingFactory, SharpDX.WIC.ContainerFormatGuids.Tiff);
     encoder.Initialize(stream);
     var bitmapFrameEncode = new SharpDX.WIC.BitmapFrameEncode(encoder);
     //bitmapFrameEncode.Options.TiffCompressionMethod = SharpDX.WIC.TiffCompressionOption.None;
     bitmapFrameEncode.Initialize();
     bitmapFrameEncode.SetSize(image.Width, image.Height);
     bitmapFrameEncode.SetPixelFormat(ref format);
     bitmapFrameEncode.WritePixels(image.Height, image.DataIntPtr, image.Width * bytesPerPixel);
     bitmapFrameEncode.Commit();
     encoder.Commit();
     bitmapFrameEncode.Dispose();
     encoder.Dispose();
     stream.Dispose();
     file.Close();
     file.Dispose();
 }
 public void Copy(UnmanagedImage a)
 {
     Win32.CopyMemory(dataIntPtr, a.dataIntPtr, (UIntPtr)(width * height * bytesPerPixel));
 }