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. jpegdll.h 2.jpegdll.lib 3.jpegdll.dll 4.jpeg.htm (Help file) 5.testjpeg.zip (VC++ Example program) . Functions in JPEG API: 1. void init_jpeg() 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_jpeg(); . 2. long showjpg(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=showjpg("c:\jpgdemo\demo.jpg",hwnd,10,10) .. 3. long show_bmp(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=showbmp("c:\jpgdemo\demo.bmp",hwnd,10,10) . 4. long jpg_to_bmp(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_bmp("c:\jpgdemo\demo.jpg","c:\temp\demo.bmp") . 5. long bmp_to_jpeg(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_jpg("c:\jpgdemo\demo.bmp","c:\temp\demo.jpg",75) . 6. long copy_to_bmp(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_bmp("c:\temp\demo.bmp",hwnd,0) . 7. long copy_to_jpeg(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_jpeg("c:\temp\demo.jpeg",hwnd,0,75) . 8. long to_clip(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_clip(hwnd,0) . 9. long clip_to_jpeg(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_jpeg("bird2.jpg",(long)(hWnd),75); . 10. long clip_to_bmp(char *name,long hl) This function save content of clipboard to a BMP file. Example: rs=clip_to_bmp("bird2.bmp",(long)(hWnd),75); . 11. void Area_Copy(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_Copy((long)(hWnd),0,0,300,400); . 12. long Area_to_jpeg(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_jpeg((long)(hWnd),0,0,300,400,"bird3.jpg",75); . 13. long Area_to_bmp(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_bmp((long)(hWnd),0,0,300,400,"bird3.bmp"); |
Example of VC++: ![]()
.
Below is main souce code of this program:
BOOL CTestDlg::OnInitDialog()
{CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
hWnd=this->m_hWnd; // get the handle of the window
init_jpeg(); // init JPEG API Libary
return TRUE;
}void CTestDlg::OnExit() // Exit
{CDialog::OnOK();}void CTestDlg::OnMenuitem32771() // Open a jpeg file
{showjpg("bird.jpg",(long)(hWnd),2,2);}void CTestDlg::OnMenuitem32772() // Copy Window to a jpeg file
{copy_to_jpeg((long)(hWnd),"bird1.jpg",1,75);}void CTestDlg::OnBmpReadbirdbmp() // Read BMP file
{show_bmp("bird.bmp",(long)(hWnd),2,2);}void CTestDlg::OnBmpSavetobird1bmp() // Save to BMP
{copy_to_bmp((long)(hWnd),"bird1.bmp",1);}void CTestDlg::OnFileJpegtobmp() // JPEG to BMP
{jpg_to_bmp("bird.jpg","bird1.bmp");}void CTestDlg::OnFileBmptojpeg() // BMP to JPEG
{bmp_to_jpg("bird.bmp","bird1.jpg",75);}void CTestDlg::OnClipboardCopytoclipboard() // Copy to Clipboard
{to_clip((long)(hWnd),0);}void CTestDlg::OnClipboardClipboardtojpeg() // Clipboard to JPEG
{clip_to_jpeg("bird2.jpg",(long)(hWnd),75);}void CTestDlg::OnClipboardClipboardtobmp() // Clipboard to BMP
{clip_to_bmp("bird2.bmp",(long)(hWnd));}void CTestDlg::OnClipboardCopyareatoclipboard() // Copy Area
{Area_Copy((long)(hWnd),0,0,300,400);}void CTestDlg::OnClipboardPasteareatobird3jpg() // Copy Area to a JPEG file
{Area_to_jpeg((long)(hWnd),0,0,300,400,"bird3.jpg",75);}void CTestDlg::OnClipboardCopyareatobird3bmp() // Copy Area to a BMP file
{Area_to_bmp((long)(hWnd),0,0,300,400,"bird3.bmp");}