Poszukuje jakiegoś przyjemnego i krótkiego sposobu na konwersje formatu .bmp do .jpg. Cały program ma za zadanie wykonywanie zrzutu ekranu do pliku, więc gdyby ktoś posiadał funkcje zapisu takowych plików w formacie jpg byłbym wdzieczny. Obecny wyglad funkcji:
HDC hScreen, hCompat;
HBITMAP hBm;
BITMAP bmp;
BITMAPINFO bmpinfo;
LPVOID pBits;
DWORD dwWidth, dwHeight, dwBPP, dwNumColors, dwBytes;
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
RGBQUAD colors[256];
HANDLE hfile;
int iRet;
CreateDirectory("~tmp",0);
// the original image dimensions, before we made them divisible by 8
WORD Ximage_original, Yimage_original;
// cleanup
ZeroMemory( &bmp, sizeof( bmp ) );
ZeroMemory( &bmpinfo, sizeof( bmpinfo ) );
ZeroMemory( &bitmapfileheader, sizeof( bitmapfileheader ) );
ZeroMemory( &bitmapinfoheader, sizeof( bitmapinfoheader ) );
ZeroMemory( &colors, sizeof( colors ) );
// desktop
hScreen = CreateDC( "DISPLAY", NULL, NULL, NULL );
dwWidth = GetDeviceCaps( hScreen, HORZRES );
dwHeight = GetDeviceCaps( hScreen, VERTRES );
dwBPP = 16; //dwBPP = GetDeviceCaps( hScreen, BITSPIXEL );
dwNumColors = GetDeviceCaps( hScreen, NUMCOLORS );
hCompat = CreateCompatibleDC( hScreen );
bmpinfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
bmpinfo.bmiHeader.biWidth = dwWidth;
bmpinfo.bmiHeader.biHeight = dwHeight;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = (WORD)dwBPP;
bmpinfo.bmiHeader.biCompression = BI_RGB;
bmpinfo.bmiHeader.biSizeImage = 0;
bmpinfo.bmiHeader.biXPelsPerMeter = 0;
bmpinfo.bmiHeader.biYPelsPerMeter = 0;
bmpinfo.bmiHeader.biClrUsed = dwNumColors;
bmpinfo.bmiHeader.biClrImportant = dwNumColors;
hBm = CreateDIBSection( hScreen, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0 );
SelectObject( hCompat, hBm );
BitBlt( hCompat, 0, 0, dwWidth, dwHeight, hScreen, 0, 0, SRCCOPY );
// BMP
if ( dwNumColors != 0 )
dwNumColors = GetDIBColorTable( hCompat, 0, dwNumColors, colors );
bitmapfileheader.bfType = 0x4D42;
bitmapfileheader.bfSize = ((dwWidth * dwHeight * dwBPP)/8) + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapfileheader.bfReserved1 = 0;
bitmapfileheader.bfReserved2 = 0;
bitmapfileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapinfoheader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfoheader.biWidth = dwWidth;
bitmapinfoheader.biHeight = dwHeight;
bitmapinfoheader.biPlanes = 1;
bitmapinfoheader.biBitCount = (WORD)dwBPP;
bitmapinfoheader.biCompression = BI_RGB;
bitmapinfoheader.biSizeImage = 0;
bitmapinfoheader.biXPelsPerMeter = 0;
bitmapinfoheader.biYPelsPerMeter = 0;
bitmapinfoheader.biClrUsed = dwNumColors;
bitmapinfoheader.biClrImportant = 0;
hfile = CreateFile( nazwa_ss, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
WriteFile( hfile, &bitmapfileheader, sizeof(BITMAPFILEHEADER), &dwBytes, NULL );
WriteFile( hfile, &bitmapinfoheader, sizeof(BITMAPINFOHEADER), &dwBytes, NULL );
if ( dwNumColors != 0 )
WriteFile( hfile, colors, sizeof(RGBQUAD) * dwNumColors, &dwBytes, NULL );
WriteFile( hfile, pBits, (dwWidth*dwHeight*dwBPP)/8, &dwBytes, NULL );
CloseHandle( hfile );
DeleteObject( hBm );
DeleteDC( hScreen );
DeleteDC( hCompat );
}
Wykonuje ona prawidłowy zrzut ekranu w formacie .bmp. Satysfakcjonują mnie 2 rozwiazania:
a)przerobienie tej funkcji aby zapisywala plik jpg.
b)nowa funkca która czytałaby zapisany plik, konwertowała go i zapisywałą w miejsce .bmp
Z góry dziękuje za wszelke próby pomocy.