Converting to JPEG, (JPG). 
Author Message
 Converting to JPEG, (JPG).

Hi,

I am doing a screen capture and, using the code below, I can save in a BMP
format.
But how can I achieve the same the file in a JPG format? Or any other format
that is a lot more compressed than BMP?

//////////////////////////////////////
//    code to save in BMP
//////////////////////////////////////

BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
...
bmpInfo.bmiHeader.biCompression = BI_RGB;

...
void *pvBits = NULL;
HBITMAP hBitmap =
CreateDIBSection(hdcScreen,&bmpInfo,DIB_RGB_COLORS,&pvBits,NULL,0);
HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcCompatible,hBitmap);
BOOL b =
BitBlt(hdcCompatible,0,0,iScrWidth,iScrHeight,hdcScreen,0,0,SRCCOPY);
HANDLE hFile = CreateFile( "yourbmp.bmp",
GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwCnt;
char z[14];
ZeroMemory(z,14);
strcpy(z,"BM8");
z[4] = 0x24;
z[10] = 0x36;
WriteFile(hFile,z,14,&dwCnt,NULL);
WriteFile(hFile,(char*)&bmpInfo,sizeof(BITMAPINFO)-4,&dwCnt,NULL);
WriteFile(hFile,(char*)pvBits,iScrWidth*iScrHeight*3,&dwCnt,NULL);
CloseHandle(hFile);

Quote:
}

SelectObject(hdcCompatible,hOldBitmap);
DeleteDC(hdcCompatible);
DeleteObject(hBitmap);
ReleaseDC(NULL,hdcScreen);

//////////////////////////////////////
//    code to save in BMP
//////////////////////////////////////

Many thanks in advance



Sat, 17 Dec 2005 22:36:16 GMT  
 Converting to JPEG, (JPG).
See if this site helps with the format conversion:

http://www.wotsit.org/


Quote:
> Hi,

> I am doing a screen capture and, using the code below, I can save in a BMP
> format.
> But how can I achieve the same the file in a JPG format? Or any other
format
> that is a lot more compressed than BMP?

> //////////////////////////////////////
> //    code to save in BMP
> //////////////////////////////////////

> BITMAPINFO bmpInfo;
> bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
> ...
> bmpInfo.bmiHeader.biCompression = BI_RGB;

> ...
> void *pvBits = NULL;
> HBITMAP hBitmap =
> CreateDIBSection(hdcScreen,&bmpInfo,DIB_RGB_COLORS,&pvBits,NULL,0);
> HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
> HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcCompatible,hBitmap);
> BOOL b =
> BitBlt(hdcCompatible,0,0,iScrWidth,iScrHeight,hdcScreen,0,0,SRCCOPY);
> HANDLE hFile = CreateFile( "yourbmp.bmp",
> GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
> CREATE_ALWAYS,
> FILE_ATTRIBUTE_NORMAL,
> NULL
> );
> if (hFile != INVALID_HANDLE_VALUE)
> {
> DWORD dwCnt;
> char z[14];
> ZeroMemory(z,14);
> strcpy(z,"BM8");
> z[4] = 0x24;
> z[10] = 0x36;
> WriteFile(hFile,z,14,&dwCnt,NULL);
> WriteFile(hFile,(char*)&bmpInfo,sizeof(BITMAPINFO)-4,&dwCnt,NULL);
> WriteFile(hFile,(char*)pvBits,iScrWidth*iScrHeight*3,&dwCnt,NULL);
> CloseHandle(hFile);
> }
> SelectObject(hdcCompatible,hOldBitmap);
> DeleteDC(hdcCompatible);
> DeleteObject(hBitmap);
> ReleaseDC(NULL,hdcScreen);

> //////////////////////////////////////
> //    code to save in BMP
> //////////////////////////////////////

> Many thanks in advance



Sat, 17 Dec 2005 23:40:45 GMT  
 Converting to JPEG, (JPG).
You need a bitmap-to-JPEG subroutine. You can find this in GDI+, or on numerous sites such
as www.codeproject.com and www.codeguru.com. You can also find GIF converters (but be
aware that the GIF algorithm is patented and you may have to pay royalties if you use it
in a product)
                                        joe

Quote:

>Hi,

>I am doing a screen capture and, using the code below, I can save in a BMP
>format.
>But how can I achieve the same the file in a JPG format? Or any other format
>that is a lot more compressed than BMP?

>//////////////////////////////////////
>//    code to save in BMP
>//////////////////////////////////////

>BITMAPINFO bmpInfo;
>bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
>...
>bmpInfo.bmiHeader.biCompression = BI_RGB;

>...
>void *pvBits = NULL;
>HBITMAP hBitmap =
>CreateDIBSection(hdcScreen,&bmpInfo,DIB_RGB_COLORS,&pvBits,NULL,0);
>HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
>HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcCompatible,hBitmap);
>BOOL b =
>BitBlt(hdcCompatible,0,0,iScrWidth,iScrHeight,hdcScreen,0,0,SRCCOPY);
>HANDLE hFile = CreateFile( "yourbmp.bmp",
>GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
>CREATE_ALWAYS,
>FILE_ATTRIBUTE_NORMAL,
>NULL
>);
>if (hFile != INVALID_HANDLE_VALUE)
>{
>DWORD dwCnt;
>char z[14];
>ZeroMemory(z,14);
>strcpy(z,"BM8");
>z[4] = 0x24;
>z[10] = 0x36;
>WriteFile(hFile,z,14,&dwCnt,NULL);
>WriteFile(hFile,(char*)&bmpInfo,sizeof(BITMAPINFO)-4,&dwCnt,NULL);
>WriteFile(hFile,(char*)pvBits,iScrWidth*iScrHeight*3,&dwCnt,NULL);
>CloseHandle(hFile);
>}
>SelectObject(hdcCompatible,hOldBitmap);
>DeleteDC(hdcCompatible);
>DeleteObject(hBitmap);
>ReleaseDC(NULL,hdcScreen);

>//////////////////////////////////////
>//    code to save in BMP
>//////////////////////////////////////

>Many thanks in advance

Joseph M. Newcomer [MVP]

Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Sun, 18 Dec 2005 00:22:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. JPG JPEG

2. Screen Capture as .jpg / .jpeg file

3. GIF/JPG/JPEG from CGI

4. error converting image from tif to jpg format

5. Converting bmp to jpg - Compression?

6. convert HTML file to BMP file (JPG, GIF ...)

7. Convert BMP to JPG in different Compression Ratio

8. Converting BMP to JPG

9. convert bitmap to jpg and to unicode

10. Anyone have routine to convert tif to jpg?

11. free code to convert bmp to jpg

12. convert HTML file to BMP file (JPG, GIF ...)

 

 
Powered by phpBB® Forum Software