Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Thu, 15 May 2008 11:51:01 -0700,    group: microsoft.public.win32.programmer.gdi        back       


save video buffer to JPEG   
There is code, which make desctop snapshot to JPG. Also there are code which 
make BMP picture captured from video VMR9 renderer. May be anybody know how 
to connect these two code sample to make captured video picture in JPG format?

These sample make desctop snapshot:

#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>

using namespace Gdiplus;


int GetEncoderClsid(WCHAR *format, CLSID *pClsid)
{
    unsigned int num = 0,  size = 0;
    GetImageEncodersSize(&num, &size);
    if(size == 0) return -1;
    ImageCodecInfo *pImageCodecInfo = (ImageCodecInfo *)(malloc(size));
    if(pImageCodecInfo == NULL) return -1;
    GetImageEncoders(num, size, pImageCodecInfo);
    for(unsigned int j = 0; j < num; ++j){
        if(wcscmp(pImageCodecInfo[j].MimeType, format) == 0){
            *pClsid = pImageCodecInfo[j].Clsid;
            free(pImageCodecInfo);
            return j;
        }   
    }
    free(pImageCodecInfo);
    return -1;
}

int GetScreeny(LPWSTR lpszFilename, ULONG uQuality)
{
    ULONG_PTR gdiplusToken;
    GdiplusStartupInput gdiplusStartupInput;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
   
    HDC hdcScreen  = CreateDC("DISPLAY", NULL, NULL, NULL);
    HDC hdcCapture = CreateCompatibleDC(hdcScreen);
    int nWidth     = GetDeviceCaps(hdcScreen, HORZRES),
        nHeight    = GetDeviceCaps(hdcScreen, VERTRES),
        nBPP       = GetDeviceCaps(hdcScreen, BITSPIXEL);
   
    LPBYTE lpCapture;
    BITMAPINFO bmiCapture = { {
        sizeof(BITMAPINFOHEADER), nWidth, -nHeight, 1, nBPP, BI_RGB, 0, 0, 
0, 0, 0,
    } };
    HBITMAP hbmCapture = CreateDIBSection(hdcScreen, &bmiCapture,
        DIB_PAL_COLORS, (LPVOID *)&lpCapture, NULL, 0);
    if(!hbmCapture){
        DeleteDC(hdcCapture);
        DeleteDC(hdcScreen);
        GdiplusShutdown(gdiplusToken);
        return 1;
    }
   
    int nCapture = SaveDC(hdcCapture);
    SelectObject(hdcCapture, hbmCapture);
    BitBlt(hdcCapture, 0, 0, nWidth, nHeight, hdcScreen, 0, 0, SRCCOPY);
    RestoreDC(hdcCapture, nCapture);
    DeleteDC(hdcCapture);
    DeleteDC(hdcScreen);
   
    CLSID imageCLSID;
    Bitmap *pScreenShot = new Bitmap(hbmCapture, (HPALETTE)NULL);
    EncoderParameters encoderParams;
    encoderParams.Count = 1;
    encoderParams.Parameter[0].NumberOfValues = 1;
    encoderParams.Parameter[0].Guid  = EncoderQuality;
    encoderParams.Parameter[0].Type  = EncoderParameterValueTypeLong;
    encoderParams.Parameter[0].Value = &uQuality;
    GetEncoderClsid(L"image/jpeg", &imageCLSID);
    int result = (pScreenShot->Save(lpszFilename, &imageCLSID, 
&encoderParams) == Ok);
    delete pScreenShot;
    DeleteObject(hbmCapture);
    GdiplusShutdown(gdiplusToken);
    return result;
}

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int 
nShowCmd)
{
    return GetScreeny(L"screeny.jpg", 75);
}

These code make BMP picture from captured video:

void photo (void)
{           
 m_pControl->Pause();
 // get width and height
 long height, width;
 pBasicVideo->get_VideoHeight(&height);
 pBasicVideo->get_VideoWidth(&width);

 long bufSize;
 long *imgData;
 HRESULT hr;
 /*
 The second value is NULL to resolve required buffer size.
 The required buffer size will be returned in variable "bufSize".
 */
 hr = pBasicVideo->GetCurrentImage(&bufSize, NULL);
 if (FAILED(hr)) {
     return 1;
 }
 if (bufSize < 1) {
     return 1;
 }
 imgData = (long *)malloc(bufSize);

 // The data will be in DIB format
 pBasicVideo->GetCurrentImage(&bufSize, imgData);

 // save DIB file as Bitmap.
 // This sample saves image as bitmap to help
 // understanding the sample.
 HANDLE fh;
 BITMAPFILEHEADER bmphdr;
 BITMAPINFOHEADER bmpinfo;
 DWORD nWritten;

 memset(&bmphdr, 0, sizeof(bmphdr));
 memset(&bmpinfo, 0, sizeof(bmpinfo));

 bmphdr.bfType = ('M' << 8) | 'B';
 bmphdr.bfSize = sizeof(bmphdr) + sizeof(bmpinfo) + bufSize;
 bmphdr.bfOffBits = sizeof(bmphdr) + sizeof(bmpinfo);
 bmpinfo.biSize = sizeof(bmpinfo);
 bmpinfo.biWidth = width;
 bmpinfo.biHeight = height;
 bmpinfo.biPlanes = 1;
 bmpinfo.biBitCount = 24;

 fh = CreateFile(_T("C:\\img.bmp"),
     GENERIC_WRITE, 0, NULL,
     CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

 WriteFile(fh, &bmphdr, sizeof(bmphdr), &nWritten, NULL);
 //WriteFile(fh, &bmpinfo, sizeof(bmpinfo), &nWritten, NULL);
 WriteFile(fh, imgData, bufSize, &nWritten, NULL);
 
 CloseHandle(fh);
 free(imgData);

 // Release resource
 m_pControl->Run();
 return 0;
}
date: Thu, 15 May 2008 11:51:01 -0700   author:   vdm

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us