Home

Win32 JPEG API


I have been looking for a long time for a JPEG package that will allow me to show a JPEG file or save screen to a JPEG file in my program, espically in Visual FoxPro or Visual Basic. I never found one that didn't cost hundreds of dollars and didn't need complicated programming. Thanks for excellent works of Independent JPEG Group's software of  IJG JPEG library and thanks for CHRISDL@PAGESZ.NET's MFC examples,  I  wrote a win32 JPEG api dll by my myself.  You can call it to show a JPEG file in your program by only one sentence: showjpg(fliename,hwnd,left,top) . No more is needed to know.Below is a screen shot of a form of VFP5.0: 

.
JPEG API is a freeware, you can use and distribute it freely. Press here to download.


JPEG API package include four file:
1. jpgdll.h (For VC++ and FoxPro )
2.jpgdll.lib (For VC++ and FoxPro )
3.jpgdll.dll (For VC++ and FoxPro )
8.jpegtest_vc.zip (VC++ Example program)
9.jpegtest_vb.zip (VB Example program)
.
Functions in  JPEG API:
1. void init_jpeg1() 
This function initiate JPEG API library, it must be called before any other functions. You only need to call it once in your program.
Example: init_jpeg1();
.
2. void findwindow1(char *title)
This function find the handle of the window, which is needed by other functions.
Title is the title of the window. If the title of the window is long, use first few words. 
Example: hl=findwindow1("JPEG TEST");
.
3. long showjpg1(char *fliename, long hwnd, long left, long top)
This function show a JPG file in a window at (left,top). Here hwnd is handle of the window. If return 1, then all is ok.
Example: rs=showjpg1("c:\jpgdemo\demo.jpg",hwnd,10,10)
..
4. long show_bmp1(char *fliename, long hwnd, long left, long top)
This function show a bmp file in a window at (left,top). Here hwnd is handle of the window. If return 1, then all is ok.
Example: rs=showbmp1("c:\jpgdemo\demo.bmp",hwnd,10,10)
.
5. long  jpg_to_bmp1(char *jpgfilename, char *bmpfilename)
This function copy a JPG file to a BMP file.  If return 1, then all is ok.
Example:rs=jpg_to_bmp1("c:\jpgdemo\demo.jpg","c:\temp\demo.bmp")
.
6. long bmp_to_jpg1(char *jpgfilename, char *bmpfilename,long quality)
This function copy a BMP file to a JPG file.  Quality=Quality of JPEG file, usually 75.
If return 1, then all is ok.
Example:rs=bmp_to_jpg1("c:\jpgdemo\demo.bmp","c:\temp\demo.jpg",75)
.
7. long copy_to_bmp1(long hwnd, char *bmpfilename, long type)
This function copy a screen shot of a window to a BMP file. 
Type=0, copy all window; Type=1, copy client area
Example: rs=copy_to_bmp1("c:\temp\demo.bmp",hwnd,0)
.
8. long copy_to_jpeg1(long hwnd, char *bmpfilename, long type,long quality)
This function copy a screen shot of a window to a JPEG file. 
Type=0, copy all window; Type=1, copy client area
Quality=Quality of JPEG file, usually 75.
Example: rs=copy_to_jpeg1("c:\temp\demo.jpeg",hwnd,0,75)
.
9. long to_clip1(long hwnd, long type)
This function copy a screen shot of a window(like above) to the clipboard, then you can paste it to any picture program to edit. Type=0, copy all window; Type=1, copy client area
Example:rs=to_clip1(hwnd,0)
.
10. long clip_to_jpeg1(char *name,long hl,long quality)
This function save content of clipboard to a JPEG file.
Quality=Quality of JPEG file, usually 75.
Example:rs=clip_to_jpeg1("bird2.jpg",hWnd,75);
.
11. long clip_to_bmp1(char *name,long hl)
This function save content of clipboard to a BMP file.
Example:rs=clip_to_bmp1("bird2.bmp",hWnd,75);
.
12. void Area_Copy1(long hl,long left,long top,long w,long h)
This function copy a area to clipboard. The left corner position of area is  (left,top), the area width is w, the area height is h.
Example:Area_Copy1(hWnd,0,0,300,400);
.
13. long Area_to_jpeg1(long hl,long left,long top,long w,long h,char * name,long qa)
This function copy a area to a jpeg file. The left corner position of area is  (left,top), the area width is w, the area height is h. Quality=Quality of JPEG file, usually 75.
Example:Area_to_jpeg1(hWnd,0,0,300,400,"bird3.jpg",75);
.
14. long Area_to_bmp1(long hl,long left,long top,long w,long h,char * name)
This function copy a area to a bmp file. The left corner position of area is  (left,top), the area width is w, the area Example:Area_to_bmp1(hWnd,0,0,300,400,"bird3.bmp");
 
Example of VB:

Below is main souce code of this program:
Private Declare Function init_jpeg1 Lib "jpgdll.dll" () As Long
Private Declare Function findwindow1 Lib "jpgdll.dll" (ByVal name As String) As Long
Private Declare Function showjpg1 Lib "jpgdll.dll" (ByVal name As String, ByVal hd As Long, ByVal l As Long, ByVal t As Long) As Long
Private Declare Function to_clip1 Lib "jpgdll.dll" (ByVal hl As Long, ByVal t As Long) As Long

Private Sub Command3_Click()
Dim rc As Long
rc = init_jpeg1()
End Sub

Private Sub Command1_Click()
Dim rc As Long
Dim hl As Long
Dim name As String
name = Text1.Text
hl = findwindow1("JPEG TEST")
rc = showjpg1(name, hl, 2, 2)
End Sub

Private Sub Command2_Click()
Dim rc As Long
Dim hl As Long
hl = findwindow1("JPEG TEST")
rc = to_clip1(hl, 0)
End Sub

 
Example of VC++:

Below is main souce code of this program:
//=================================================================
BOOL CTestDlg::OnInitDialog()
{CDialog::OnInitDialog();
 SetIcon(m_hIcon, TRUE);
 SetIcon(m_hIcon, FALSE);
 init_jpeg1();                 // init JPEG API Libary
 return TRUE; 
}

void CTestDlg::OnExit() 
{CDialog::OnOK();}

void CTestDlg::OnMenuitem32771()         // Open a jpeg file
{long hl; hl=findwindow1("JPEG API");
 showjpg1("birdc.jpg",hl,2,2);
}

void CTestDlg::OnMenuitem32772()         // Copy Window to a jpeg file 
{long hl; hl=findwindow1("JPEG API");
 copy_to_jpeg1(hl,"bird1.jpg",1,75);
}

void CTestDlg::OnBmpReadbirdbmp() // Read BMP file
{long hl; hl=findwindow1("JPEG API");
 show_bmp1("bird.bmp",hl,2,2);
}

void CTestDlg::OnMenuitem32793() 
{long hl; hl=findwindow1("JPEG API");
 showjpg1("girl1.jpg",hl,2,2);
}

void CTestDlg::OnBmpSavetobird1bmp() // Save to BMP
{long hl; hl=findwindow1("JPEG API");
 copy_to_bmp1((long)(hl),"bird1.bmp",1);
}

void CTestDlg::OnFileJpegtobmp() // JPEG to BMP
{jpg_to_bmp1("bird.jpg","bird1.bmp");}

void CTestDlg::OnFileBmptojpeg() // BMP to JPEG
{bmp_to_jpg1("bird.bmp","bird1.jpg",75);}

void CTestDlg::OnClipboardCopytoclipboard() // Copy to Clipboard
{long hl; hl=findwindow1("JPEG API");
 to_clip1(hl,0);
}

void CTestDlg::OnClipboardClipboardtojpeg() // Clipboard to JPEG
{long hl; hl=findwindow1("JPEG API");
 clip_to_jpeg1("bird2.jpg",hl,75);
}

void CTestDlg::OnClipboardClipboardtobmp()  // Clipboard to BMP
{long hl; hl=findwindow1("JPEG API");
 clip_to_bmp1("bird2.bmp",hl);
}

void CTestDlg::OnClipboardCopyareatoclipboard() // Copy Area
{long hl; hl=findwindow1("JPEG API");
 Area_Copy1(hl,0,0,300,400);
}

void CTestDlg::OnClipboardPasteareatobird3jpg() // Copy Area to a JPEG file
{long hl; hl=findwindow1("JPEG API");
 Area_to_jpeg1(hl,0,0,300,400,"bird3.jpg",75);
}

void CTestDlg::OnClipboardCopyareatobird3bmp()  // Copy Area to a BMP file
{long hl; hl=findwindow1("JPEG API");
 Area_to_bmp1(hl,0,0,300,400,"bird3.bmp");
}


1999.12.20