Can someone please suggest how to save bgr101010 format .tiff file in 32bpp? My code is saving in 48bpp? Basically I want to save tiff a file with 10 bit color depth.
private void Bgr()
{
BitmapImage myBitmapImage = new BitmapImage();
BitmapSource bs = new BitmapImage(new Uri(@"img\android1.png", UriKind.Relative));
int stride = bs.PixelWidth * (bs.Format.BitsPerPixel / 8);
byte[] data = new byte[stride * bs.PixelHeight];
bs.CopyPixels(data, stride, 0);
WriteableBitmap w2Bmp = new WriteableBitmap(bs.PixelWidth, bs.PixelWidth, 96.0, 96.0,PixelFormats.Bgr101010, null);
w2Bmp.WritePixels(
new Int32Rect(0, 0, bs.PixelWidth, bs.PixelHeight),
data, stride, 0);
image1.Source = w2Bmp;
var encoder = new TiffBitmapEncoder();
BitmapFrame frame = BitmapFrame.Create(w2Bmp);
encoder.Frames.Add(frame);
using (var stream = File.Create("XXX3.tiff"))
{
encoder.Save(stream);
}
}
A cursory glance at the decompiled sources of TiffBitmapEncoder reveals that it calls a native method to actually write to the TIFF. If, even on explicitly being passed the PixelFormat to write to it chooses to write something else, it might be a limitation of the underlying TIFF encoder.
Have you tried using ImageMagick or something similar with TIFF support?