BitmapSource
以下を使用して aを aに変換していBitmap
ます。
internal static Bitmap ConvertBitmapSourceToBitmap(BitmapSource bitmapSrc)
{
int width = bitmapSrc.PixelWidth;
int height = bitmapSrc.PixelHeight;
int stride = width * ((bitmapSrc.Format.BitsPerPixel + 7) / 8);
byte[] bits = new byte[height * stride];
bitmapSrc.CopyPixels(bits, stride, 0);
unsafe
{
fixed (byte* pBits = bits)
{
IntPtr ptr = new IntPtr(pBits);
return new System.Drawing.Bitmap(
width,
height,
stride,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb, //The problem
ptr);
}
}
}
PixelFormat
しかし、のを取得する方法がわからないBitmapSource
ため、画像が壊れています。
コンテキストとして、8 または 16 グレーまたは 24 または 32 ビット カラーの tiff をロードしたいので、この手法を使用していPixelFormat
ます。保存する必要があります。私はConvertBitmapSourceToBitmap
かなり便利なので修正したいと思いますが、次のコードを BitmapSource から Bitmap を作成するためのより良い手法に置き換えることもできれば幸いです。
Byte[] buffer = File.ReadAllBytes(filename.FullName);
using (MemoryStream stream = new MemoryStream(buffer))
{
TiffBitmapDecoder tbd = new TiffBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
return BitmapBitmapSourceInterop.ConvertBitmapSourceToBitmap(tbd.Frames[0]);
}