Image loading and saving in jpeg format, is achievable in Liberty BASIC using a freely available dll.
The first example below, saves natively drawn graphics to a jpg file.
'Saving graphics drawn with native commands, to a jpeg file
nomainwin
open "jpgdll.dll"for dll as #conv
'initialise dll, call once in program execution
calldll #conv,"init_jpeg1",ret as void
WindowWidth=600:WindowHeight=400
open "Drawing"for graphics as #g
hW=hwnd(#g)
#g "font arial 21"
#g, "down;color red;fill yellow;backcolor yellow"
#g "place 10 50;\Saving drawn graphics\\to jpg file!"
#g "place 50 150;color green;backcolor green;boxfilled 200 300"
#g, "flush"'VB Example: 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=1'0= copy all window; 1= copy client area
quality=100'Quality of JPEG file, usually 75.'VB Example: rs=copy_to_jpeg1("c:\temp\demo.jpeg",hwnd,0,75)
jpgfilename$=DefaultDir$+"\screen.jpg"
calldll #conv,"copy_to_jpeg1",hW asulong,jpgfilename$ as ptr, Type aslong,quality aslong,res aslong
close #conv
wait
Functions included in the dll are listed below in VB format but are easy to translate to Liberty BASIC format
Function list from website http://heliso.tripod.com/programm/jpeg/jpeg.htm
The dll can be extracted from http://heliso.tripod.com/programm/jpeg/jpegAll.rar
NOTE: there are some errors in this document, which have been corrected.There may
be others.I have not tested every function.Functionsin JPEG API:
1.void init_jpeg1()
This function initiate JPEG API library, it must be called before any other functions.You only need tocall 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.Titleis the title of the window.If the title of the window islong, 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.Ifreturn1, 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.Ifreturn1, 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.Ifreturn1, then all is ok.Example:rs=jpg_to_bmp1("c:\jpgdemo\demo.jpg","c:\temp\demo.bmp").6.long bmp_to_jpg1(char*bmpfilename, char*jpgfilename,long quality)*web info incorrect!
This function copy a BMP file to a JPG file.Quality=Quality of JPEG file, usually 75.Ifreturn1, 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(hwnd,"c:\temp\demo.jpeg",0,75)*web info incorrect!.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");
Below are examples of some of the functions translated to LB format, showing what can be achieved using jpgdll.dll
A 400x300 bitmap file 11.bmp is included for convenience but you can use any bmp file of your own. The demo will only show a
section of the bitmap if it is larger than the window.
'Demo for some jpg loading & saving functions in jpgdll.dll'This dll although rather large in size, does give LB4 users the ability to save images in'jpg format.'There are 14 listed functions, shown above in VB format.'Some functions are translated below, the remainder are easy to convert.
nomainwin
WindowWidth=500:WindowHeight=400
open "jpgdll.dll demo"for text as #1
#1, "!trapclose [quit]"
open "jpgdll.dll"for dll as #conv
dllOpen=1
#1, "jpgdll.dll demo";chr$(13)
#1 DefaultDir$
calldll #conv,"init_jpeg1",ret as void 'initialise dll, call once in program execution'save a bmp as jpg
bmpfilename$=DefaultDir$+"\11.bmp"
jpgfilename$=DefaultDir$+"\11.jpg"
quality=75
calldll #conv,"bmp_to_jpg1",bmpfilename$ as ptr,jpgfilename$ as ptr,quality aslong,res aslong'If return 1, then all is ok.
#1, res
'copy jpg to bmp
jpgfilename$=DefaultDir$+"\11.jpg"
bmpfilename$=DefaultDir$+"\copyof11.bmp"
calldll #conv, "jpg_to_bmp1",jpgfilename$ as ptr,bmpfilename$ as ptr,res aslong
#1, res
'open graphics window
WindowWidth=460:WindowHeight=360
open "Test jpg"for graphics as #g
#g "trapclose [quitg]"
gOpen=1
hGB=hwnd(#g)'show jpg in window. NOTE image does not stick
calldll #conv,"showjpg1",jpgfilename$ as ptr, hGB asulong,0aslong,0aslong,_
res aslong'show bmp in window'calldll #conv,"show_bmp1", bmpfilename$ as ptr,hGB as ulong,0 as long,0 as long,_'res as long'Example: rs=showjpg1("c:\jpgdemo\demo.jpg",hwnd,10,10)
#1, res
'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=1'0= copy all window; 1= copy client area
quality=75'Quality of JPEG file, usually 75.'Example: rs=copy_to_jpeg1("c:\temp\demo.jpeg",hwnd,0,75)
jpgfilename$=DefaultDir$+"\screen.jpg"
calldll #conv,"copy_to_jpeg1",hGB asulong,jpgfilename$ as ptr, Type aslong,_
quality aslong,res aslong
#1, res
'long Area_to_jpeg1(long hl,long left,long top,long w,long h,char * name,long quality)'This function copies an 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)
x1=100:y1=1:w=200:h=100
quality=75
jpgfilename$=DefaultDir$+"\screenAreaJPG.jpg"
calldll #conv,"Area_to_jpeg1",hGB asulong,x1 aslong,y1 aslong,w aslong,h aslong,_
jpgfilename$ as ptr, quality aslong,res aslong
#1, res
'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");
x1=100:y1=1:w=200:h=100
jpgfilename$=DefaultDir$+"\screenAreaBMP.bmp"
calldll #conv,"Area_to_bmp1",hGB asulong,x1 aslong,y1 aslong,w aslong,h aslong,_
jpgfilename$ as ptr,res aslong
#1, res
calldll #user32,"GetDesktopWindow",hDT asulong'long Area_to_jpeg1(long hl,long left,long top,long w,long h,char * name,long quality)'This function copies an area of the desktop 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",100)
x1=1:y1=1:w=400:h=300
jpgfilename$=DefaultDir$+"\desktopAreaJPG.bmp"
calldll #conv,"Area_to_bmp1",hDT asulong,x1 aslong,y1 aslong,w aslong,h aslong,_
jpgfilename$ as ptr, res aslong
#1, res
close #conv
dllOpen=0
wait
[quitg]
close #g
gOpen=0
wait
[quit]if dllOpen then close #conv
if gOpen then close #g
close #1end
Image loading and saving in jpeg format, is achievable in Liberty BASIC using a freely available dll.
The first example below, saves natively drawn graphics to a jpg file.
jpgdll.dll can be downloded free from here
Functions included in the dll are listed below in VB format but are easy to translate to Liberty BASIC formatBelow are examples of some of the functions translated to LB format, showing what can be achieved using jpgdll.dll
A 400x300 bitmap file 11.bmp is included for convenience but you can use any bmp file of your own. The demo will only show asection of the bitmap if it is larger than the window.