Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Re external libraries, that would depend on your OS and compiler. Using Microsoft Visual C++ you can use a TiffBitmapDecoder object. The code below may be overly complicated but it should work.

Stream^ imageStreamSource = gcnew FileStream(FileName, FileMode::Open, FileAccess::Read, FileShare::Read);
TiffBitmapDecoder^ decoder = gcnew TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapSource^ bitmapSource = decoder->Frames[FrameNumber];
int width=bitmapSource->PixelWidth;
int height=bitmapSource->PixelHeight;
int bitsPerPixel=bitmapSource->Format.BitsPerPixel; 
Type=;//you'll need to figure this one out
int stride = (width * bitsPerPixel + 7) / 8;//this may need to change for color images
array<System::Byte>^ pixels = gcnew array<System::Byte>(height * stride);
Mat Img=Mat(Height,Width,Type,&pixels[0],Stride);