I'm using LibTiff.NET
to read a multipage Tiff file. It's no problem to convert my Tiff into a System.Drawing.Bitmap
, since it's shown on their website, but what I want is a BitmapSource
or something comparable to use in WPF
.
Of course, I can convert the already converted System.Drawing.Bitmap
, but since the amount of data is quite big, I am looking for a method to convert directly from the Tiff object
.
Any suggestions? Maybe with the ReadRGBAImage method, that returns an int array with the colors?
Edit1:
I tried the following but only get an image consisting of gray stripes:
int[] raster = new int[height * width];
im.ReadRGBAImage(width, height, raster);
byte[] bytes = new byte[raster.Length * sizeof(int)];
Buffer.BlockCopy(raster, 0, bytes, 0, bytes.Length);
int stride = raster.Length / height;
image.Source = BitmapSource.Create(
width, height, dpiX/*ex 96*/, dpiY/*ex 96*/,
PixelFormats.Indexed1, BitmapPalettes.BlackAndWhite, bytes,
/*32/*bytes/pixel * width*/ stride);
Edit2:
Maybe this helps, it is for conversion to System.Drawing.Bitmap
.