Image Loading Error

BlitzPlus Forums/BlitzPlus Programming/Image Loading Error

William Drescher(Posted 2007) [#1]
I can't get an image to load into my program. The program uses the GUI codes with a canvas. Here's a small example of my code:

Global Toolbarimage=LoadAnimImage("data\toolbar.png",24,30,0,70)
MaskImage ToolbarImage,255,255,255

Global window=createwindow("Window",0,0,700,500,0,1)
Global canvas=CreateCanvas(0,0,ClientWidth(window),ClientHeight(window),window)

Repeat
    Select WaitEvent(1)
        Case $803 : Exit
    
        Default
            SetBuffer CanvasBuffer(canvas)
            Cls
            DrawImage Toolbarimage,5,5,29
            FlipCanvas(canvas)

    End Select
Forever
End


The program breaks at the maskimage point and says invalid image handle.


b32(Posted 2007) [#2]
It sounds like the image is not loaded, try if the variable ToolbarImage is zero.
And the file, can it be found ? Try if
Print FileType("data\toolbar.png")
returns a 1 ? -->if not, file is not found
Have you tried loading the image with LoadImage ?
And the size of the toolbar image, can it contain 70 frames@24x30 ? Have you tried loading another image (.bmp?)


rdodson41(Posted 2007) [#3]
Yeah like b32 said make sure the path is valid, but also make sure that the program is saved to disk, because I seem to remember that B+ programs would not load images until the actual program code had been saved to disk as whatever like ImageProgram.bb. Probably had something to do with a bad path.


William Drescher(Posted 2007) [#4]
The images dimensions are 336x120 and each frame is 24x30 so there are 70 frames. The debugger sometimes doesn't work either. If I look up the globals in the debugger, they all appear 0, but all of them except the images work. The file is being recognized but is lost when i load it. I've changed it to .bmp and it won't load it either and LoadImage() doesn't work with either .jpg or .bmp.


Dabz(Posted 2007) [#5]
Any chance you could post the toolbar image, without that, its anyones guess whether its the path or not!

Dabz


Andy_A(Posted 2007) [#6]
There's only 56 frames not 70

336/24 = 14
120/30 = 4

14*4 = 56


William Drescher(Posted 2007) [#7]
Ok, I have revised the toolbar image, so that the dimensions fit the number of frames and I've removed some frames in the image to make it more practical. I'll try and post the image so that you can see it.

Edit: Here are the images:
This is the normal one:


This is the Right-To-Left one:



b32(Posted 2007) [#8]
If you keep the .bb file and the .png file in the same directory, it seems to work with this code:



William Drescher(Posted 2007) [#9]
Yes, that is quite interesting...I might be able to set the currentdir() to the "data" directory and see if it loads it that way. Thanks for the help.

Edit: Has anyone else noticed that if you mask the image, it messes with the color?


Dabz(Posted 2007) [#10]

Has anyone else noticed that if you mask the image, it messes with the color?



Quite understandable since in the above code white is the mask colour, and in the image above... There's loads of white in there.

I personally use 255,0,255 (Pink), as its very very very rare I'd use such a gay colour! :)

Dabz


William Drescher(Posted 2007) [#11]
That's interesting, but if i try and change the background color in ANY image editor then it still screws with the color, there isn't any way out! :(


Floyd(Posted 2007) [#12]
A flood fill would change most of the background correctly. You would still need to do a little manual editing, e.g. the finger holes in the scissors.


xlsior(Posted 2007) [#13]
That's interesting, but if i try and change the background color in ANY image editor then it still screws with the color, there isn't any way out! :(


*how* does it 'screw with the color'?

Does the changed image look OK to you visually, or are you saying that the background overwrites parts of the image it shouldn't?

If the latter: Most paint programs allow you to specify a 'tolerance' for a floodfill, specifying how picky they need to be. The smaller the tolerance, the less 'similar' colors it will overwrite in the process during a floodfill.