C# 将Tiff内存流转换为位图

C# 将Tiff内存流转换为位图,c#,bitmap,office-interop,tiff,C#,Bitmap,Office Interop,Tiff,我正在使用Outlook加载项转换附件。尝试将Tiff附件转换为位图时,我得到: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException。已加载的方法System.Windows.Media.Imaging.TiffBitmapDecoder.TiffBitmapDecoder具有无效参数 守则: const string PR_ATTACH_DATA_BIN = "http://schemas.microsoft.com/mapi/propt

我正在使用Outlook加载项转换附件。尝试将Tiff附件转换为位图时,我得到:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException。已加载的方法System.Windows.Media.Imaging.TiffBitmapDecoder.TiffBitmapDecoder具有无效参数

守则:

const string PR_ATTACH_DATA_BIN = "http://schemas.microsoft.com/mapi/proptag/0x37010102";

// Retrieve the attachment as a byte array
var attachmentData = myOutlookAttachement.PropertyAccessor.GetProperty(PR_ATTACH_DATA_BIN);

TiffBitmapDecoder decoder = new TiffBitmapDecoder(attachmentData, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
Bitmap bmp = new Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

多亏了Alex K,我找到了答案:

const string PR_ATTACH_DATA_BIN = "http://schemas.microsoft.com/mapi/proptag/0x37010102";

    // Retrieve the attachment as a byte array
    var attachmentData = myOutlookAttachement.PropertyAccessor.GetProperty(PR_ATTACH_DATA_BIN);
    Stream stream = new MemoryStream(attachmentData);

    TiffBitmapDecoder decoder = new TiffBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
    BitmapSource bitmapSource = decoder.Frames[0];
    Bitmap bmp = new Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

那么你想在流中添加一个字节[]解决了,我没有意识到ByteArray和Stream之间的区别。非常感谢