Code archives/Miscellaneous/Verify LoadImage() and LoadAnimImage()
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Use these two function in place of the standard LoadImage() and LoadAnimImage(). If the image requested does not exists, an error message will inform the user which image is missing. This is much nicer thn the "exception" error messages and much cleaner than coding a check for every image used. Feel free to send any comments my way! -Steve | |||||
;-------------------------------------------------; ; vLoadImage ; ;------------------------------------------------- Function vLoadImage(file$) pointer = LoadImage(file$) If Not pointer Then RuntimeError ("Error loading file [" + file$ + "].") End Else Return pointer EndIf End Function ;-------------------------------------------------; ; vLoadAnimImage ; ;------------------------------------------------- Function vLoadAnimImage(file$,CellWidth,CellHeight,FirstCell,CellCount) pointer = LoadAnimImage(file$,CellWidth,CellHeight,FirstCell,CellCount) If Not pointer Then RuntimeError ("Error loading file [" + file$ + "].") End Else Return pointer EndIf End Function |
Comments
| ||
much cleaner than coding a check for every image used How do you load multiple images with this code, when you can't change the "pointer" variable? |
| ||
Pointer is local to the vLoad functions, and is newly created every time they are called. Even if it were a global (it's not, "it" is two unrelated local variables), you'd still be able to change it; that's what variables are for. |
| ||
It says "Use these two function in place of the standard LoadImage", so that confused me. I guess this is how you use it : |
| ||
No, that code will cause a memory leak. Use like this:pic1=vLoadImage("image1.png") pic2=vLoadImage("image2.png") DrawImage pic1,10,10 DrawImage pic2,180,10 WaitKey End i.e. if you choose to use these functions, do not use regular LoadImage and LoadAnimImage at all. These are replacements. |
Code Archives Forum