0

I'm working on a Outlook add-in that's converts attachments. When trying to convert an Tiff attachment to a Bitmap I get:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException. Oveloaded method System.Windows.Media.Imaging.TiffBitmapDecoder.TiffBitmapDecoder has invallid arguments.

The code:

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.
  • 171,639
  • 30
  • 264
  • 288
Jan-WIllem
  • 91
  • 13
  • 1
    So you want a byte[] to a Stream? - https://stackoverflow.com/questions/4736155/how-do-i-convert-struct-system-byte-byte-to-a-system-io-stream-object-in-c – Alex K. Aug 02 '19 at 13:50
  • Solved, I Didn't realize the difference between ByteArray and Stream. Thanks verry much – Jan-WIllem Aug 02 '19 at 14:16

1 Answers1

1

Thanks to Alex K I found the answer:

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);
Jan-WIllem
  • 91
  • 13