{"id":602,"date":"2008-08-24T13:30:29","date_gmt":"2008-08-24T11:30:29","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=602"},"modified":"2011-03-04T22:18:18","modified_gmt":"2011-03-04T20:18:18","slug":"how-to-save-image-to-bmp-file-from-ibasicvideo-or-vmr-windowless-interface","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/602","title":{"rendered":"How To: Save image to BMP file from IBasicVideo or VMR windowless interface"},"content":{"rendered":"<p>A simple question being asked all over again. Given <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms784633(VS.85).aspx\">IBasicVideo<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms784613(VS.85).aspx\">IBasicVideo2<\/a>, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms787170(VS.85).aspx\">IVMRWindowlessControl<\/a> or <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms787155(VS.85).aspx\">IVMRWindowlessControl9<\/a>, how to save image to file? It is easy. It is a bit easier with <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms784633(VS.85).aspx\">IBasicVideo<\/a> because it is possible to query this interface directly from graph&#8217;s interface, such as <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms785794(VS.85).aspx\">IGraphBuilder<\/a>, and the call will be forwarded to video renderer. This code assumes internal bitmap format is non-paletted, which I believe is always the case.<\/p>\n<pre><span style=\"color: #603000;\">LONG<\/span> nBufferSize <span style=\"color: #808030;\">=<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_SUCCEEDED<span style=\"color: #808030;\">(<\/span>pBasicVideo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>GetCurrentImage<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>nBufferSize<span style=\"color: #808030;\">,<\/span> <span style=\"color: #7d0045;\">NULL<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nCHeapPtr<span style=\"color: #800080;\">&lt;<\/span><span style=\"color: #603000;\">BITMAPINFO<\/span><span style=\"color: #800080;\">&gt;<\/span> pBitmapInfo<span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_THROW<span style=\"color: #808030;\">(<\/span>pBitmapInfo<span style=\"color: #808030;\">.<\/span>AllocateBytes<span style=\"color: #808030;\">(<\/span>nBufferSize<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> E_OUTOFMEMORY<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_SUCCEEDED<span style=\"color: #808030;\">(<\/span>pBasicVideo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>GetCurrentImage<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>nBufferSize<span style=\"color: #808030;\">,<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">LONG<\/span><span style=\"color: #808030;\">*<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">BITMAPINFO<\/span><span style=\"color: #808030;\">*<\/span><span style=\"color: #808030;\">)<\/span> pBitmapInfo<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800000; font-weight: bold;\">const<\/span> <span style=\"color: #603000;\">BYTE<\/span><span style=\"color: #808030;\">*<\/span> pnData <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">const<\/span> <span style=\"color: #603000;\">BYTE<\/span><span style=\"color: #808030;\">*<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader <span style=\"color: #808030;\">+<\/span> <span style=\"color: #008c00;\">1<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #696969;\">\/\/ NOTE: You might wish to handle &lt;=8 bpp bitmaps here<\/span>\r\nATLASSERT<span style=\"color: #808030;\">(<\/span>pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biBitCount <span style=\"color: #808030;\">&gt;<\/span> <span style=\"color: #008c00;\">8<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLASSERT<span style=\"color: #808030;\">(<\/span>pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biCompression <span style=\"color: #808030;\">=<\/span><span style=\"color: #808030;\">=<\/span> BI_RGB<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLASSERT<span style=\"color: #808030;\">(<\/span>pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biSizeImage<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #603000;\">BITMAPFILEHEADER<\/span> BitmapFileHeader<span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #400000;\">ZeroMemory<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>BitmapFileHeader<span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">sizeof<\/span> BitmapFileHeader<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nBitmapFileHeader<span style=\"color: #808030;\">.<\/span>bfType <span style=\"color: #808030;\">=<\/span> <span style=\"color: #0000e6;\">'MB'<\/span><span style=\"color: #800080;\">;<\/span>\r\nBitmapFileHeader<span style=\"color: #808030;\">.<\/span>bfSize <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">DWORD<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">sizeof<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">BITMAPFILEHEADER<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">+<\/span> pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biSize <span style=\"color: #808030;\">+<\/span> pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biSizeImage<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nBitmapFileHeader<span style=\"color: #808030;\">.<\/span>bfOffBits <span style=\"color: #808030;\">=<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">DWORD<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">sizeof<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">BITMAPFILEHEADER<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #808030;\">+<\/span> pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biSize<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_SUCCEEDED<span style=\"color: #808030;\">(<\/span>File<span style=\"color: #808030;\">.<\/span>Write<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>BitmapFileHeader<span style=\"color: #808030;\">,<\/span> <span style=\"color: #800000; font-weight: bold;\">sizeof<\/span> BitmapFileHeader<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_SUCCEEDED<span style=\"color: #808030;\">(<\/span>File<span style=\"color: #808030;\">.<\/span>Write<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">&amp;<\/span>pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">,<\/span> pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biSize<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\nATLENSURE_SUCCEEDED<span style=\"color: #808030;\">(<\/span>File<span style=\"color: #808030;\">.<\/span>Write<span style=\"color: #808030;\">(<\/span>pnData<span style=\"color: #808030;\">,<\/span> <span style=\"color: #808030;\">(<\/span><span style=\"color: #603000;\">DWORD<\/span><span style=\"color: #808030;\">)<\/span> pBitmapInfo<span style=\"color: #808030;\">-<\/span><span style=\"color: #808030;\">&gt;<\/span>bmiHeader<span style=\"color: #808030;\">.<\/span>biSizeImage<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A simple question being asked all over again. Given IBasicVideo, IBasicVideo2, IVMRWindowlessControl or IVMRWindowlessControl9, how to save image to file? It is easy. It is a bit easier with IBasicVideo because it is possible to query this interface directly from graph&#8217;s interface, such as IGraphBuilder, and the call will be forwarded to video renderer. This&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/602\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,10],"tags":[487,112,38,47,113,486,111],"class_list":["post-602","post","type-post","status-publish","format-standard","hentry","category-atl","category-video","tag-atl","tag-bmp","tag-c","tag-howto","tag-image","tag-video","tag-vmr"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=602"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/602\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}