Post by Tasp on Mar 14, 2021 7:18:42 GMT -5
I wasn't sure whether this should have been in API/DLL but I don't think the issue is with the DLL. Rather than LB not clearing the memory.
The concept is to add jpg ability to my program to allow the use of jpg and bmp image display.
I get a protection violation using this code after displaying a 50mb image about 8 times, however I think this is due to LB memory limit being reached.
If you run this code it will run fine, however if you watch the memory usage in Win Task Manager once this hit 650mb you start getting protection violations. You have to close LB for this memory to be released and you start again.
This program is currently handling images of around 50mb each, so it only takes a few image opens to reach the limit and crash.
This uses Alyce Watsons jpeg dll linked, linked and attached.
Although there are calls to unloadbmp, delsegment the named segment and cls, in an attempt to clear the memory this doesn't seem to be happening.
Any suggestions?
To run this code you'll need a fairly decent sized image, I recommend 50mb, it's hard coded so you can just hit the NEXT menu to reload the image.
jpeg.dll (24 KB)
The concept is to add jpg ability to my program to allow the use of jpg and bmp image display.
I get a protection violation using this code after displaying a 50mb image about 8 times, however I think this is due to LB memory limit being reached.
If you run this code it will run fine, however if you watch the memory usage in Win Task Manager once this hit 650mb you start getting protection violations. You have to close LB for this memory to be released and you start again.
This program is currently handling images of around 50mb each, so it only takes a few image opens to reach the limit and crash.
This uses Alyce Watsons jpeg dll linked, linked and attached.
Although there are calls to unloadbmp, delsegment the named segment and cls, in an attempt to clear the memory this doesn't seem to be happening.
Any suggestions?
To run this code you'll need a fairly decent sized image, I recommend 50mb, it's hard coded so you can just hit the NEXT menu to reload the image.
'jpeg.dll by Alyce Watson, 2003
'
'Thanks go to the nice people from [lbexp]
'for pointing me in the right direction!
'
'This DLL loads an image and returns a handle
'to a 24-bit memory bitmap of the image.
'
'Supported types: .jpg, .bmp, .ico, .emf, .wmf
'= jpeg, bitmap, icon, enhanced metafile,
'and windows metafile
'
'There are also functions to retrieve the
'width and height of the image.
'
'This software is presented as is, with no
'warrantees expressed or implied.
'
'This software is FREEWARE. You may use it
'any way you want, including in commercial
'applications. A credit to the author is
'not necessary, but can be included if you like.
'
'It ought to work on all 32-bit versions
'of Windows.
'
'Benchmark tests show that loading a bmp with
'this DLL is nearly three times as fast as
'loading it with LOADBMP.
'
'The three functions in the DLL are documented
'at the bottom of this code.
'
'Image filename
jname$ = DefaultDir$ + "\Maps\Images\000007.bmp"
'nomainwin
open "jpeg.dll" for dll as #j
MENU #1, "Next", "Next", [open]
open "JPEG.DLL Test" for graphics as #1
#1 "trapclose [quit]"
#1 "down; fill lightgray;flush"
hW=hwnd(#1) 'graphicbox handle
wait
[open]
cursor hourglass
'call DLL to load image
hPic=LoadImageFile(hW,jname$)
print "hPic=";hPic
if hPic=0 then
notice "Function failed."
cursor normal
wait
end if
'clear old graphics
#1 "cls;fill lightgray"
#1 "delsegment demo"
'unload previous bmp, if there is one
if hDemo <> 0 then unloadbmp "demo" : print "unloaded bmp demo"
'load image with LOADBMP
loadbmp "demo",hPic
hDemo=hbmp("demo")
Print "Loaded bmp demo :";hDemo
'display with DRAWBMP
#1 "drawbmp demo 0 0 ; flush demo"
cursor normal
wait
[quit]
if hDemo<>0 then
unloadbmp "demo"
print "image unloaded"
end if
close #1:close #j:end
Function LoadImageFile(hWnd, file$)
'Supported types; bmp,emf,wmf,jpg,ico
'Requires window handle,
'and disk file name of image.
'Returns handle to bmp in memory
calldll #j, "LoadImageFile",_
hWnd as ulong,_
file$ as ptr,_
LoadImageFile as ulong
End Function
Function ImageWidth(hImage)
'input handle of memory bmp
'returns width of image
calldll #j, "ImageWidth",hImage as long,_
ImageWidth as ulong
End Function
Function ImageHeight(hImage)
'input handle of memory bmp
'returns height of image
calldll #j, "ImageHeight",hImage as long,_
ImageHeight as ulong
End Function
jpeg.dll (24 KB)