'Invalid Image Handle'
Blitz3D Forums/Blitz3D Beginners Area/'Invalid Image Handle'
| ||
Any idea why I'm getting this error for this code? A .bmp called 'player' is clearly in the BlitzPlus folder. ----- Global gfxplayer Graphics 640,480,16 SetBuffer BackBuffer() gfxplayer=LoadImage("player.bmp") While Not KeyHit(1) Cls DrawImage gfxplayer,MouseX(),MouseY() Flip Wend |
| ||
The file should be in the same place as you have saved your source file. |
| ||
Cheers, skidracer. Pretty obvious now I come to think of it. :embarrassed: |
| ||
MY ONE DONT WORK EITHER IT ANNOYING |
| ||
Hi Dr.Dink, I am new to Blitz3D but I can confirm that the code above does work if the image is saved in the same directory as your source code, if you haven't saved your source code it will not work. Also make sure that the file type is bitmap. |
| ||
I'm making a rendering program in BlitzPlus for an automatic painting program that randomly generates 640x480 pictures and I keep getting this error. The rendering program is completely separate from the painting program.AppTitle "Rendering Picture..." Graphics 640,480,32,2 SetBuffer BackBuffer() Dim colors(640,480,3) Dim Rave(160,240) Dim Gave(160,240) Dim Bave(160,240) picture=LoadImage("D:\Programming\Paintings\painting0.png") ;It won't even work with the full path to the picture, the program is in the same folder DrawImage picture,0,0 Flip For y=0 To 479 For x=0 to 639 GetColor x,y colors(x,y,0)=ColorRed() colors(x,y,1)=ColorGreen() colors(x,y,2)=ColorBlue() Next Next For y=0 To 479 Step 4 For x=0 To 639 Step 4 Rave(x/4,y/4)=(colors(x,y,0)+colors(x+4,y,0)+colors(x,y+4,0)+colors(x+4,y+4,0))/4 Gave(x/4,y/4)=(colors(x,y,1)+colors(x+4,y,1)+colors(x,y+4,1)+colors(x+4,y+4,1))/4 Bave(x/4,y/4)=(colors(x,y,2)+colors(x+4,y,2)+colors(x,y+4,2)+colors(x+4,y+4,2))/4 DebugLog "R: " + Rave(x/4,y/4) + "---G: " + Gave(x/4,y/4) + "---B : " + Bave(x/4,y/4) ;For testing the code up to this point Next Next |
| ||
some things to try : -check if the image is not corrupted (open it with the windows image viewer or with an image editor) -check if the path is correct (or put the image in the same directory than your .bb/.exe) -check if the filename is correct (in the name of the file and in your bb code) -check if a reference exists after you have tried to load the image Image = loadimage("Image.jpg") debuglog(Image) -try to draw the image on the screen and stop the program just after : setbuffer(backbuffer()) clscolor(000,000,000) cls() drawimage(Image,0,0) flip() waitkey() -try to do the same thing with another image -try to do the same thing with another file format (maybe your image editor exporter for this file format is incompatible with the Blitz3d importer for this file format) if after all of this, you still get the error, post a simplified code with your file (or a similar file) that we can run and test on our side |
| ||
Hi DodgeCodingOwner, It owuld be really helpful if you could describe exactly what "error" it is you are getting. Does Blitz fail to compile, return an actual error message on execution, or is the code simply not working as expected? The code you have posted will return 0 for the ColorRed(),ColorGreen() and ColorBlue() results every time since you perform GetColor() AFTER the Flip statement. GetColor ALWAYS operates on the current GraphicsBuffer() Which you have set as SetBuffer BackBuffer() at the beginning. After the Flip, the mage drawn to the backbuffer is swapped to the frontbuffer for display, and nothing else is drawn to the BackBuffer. I suspect the following is more what you hoped for: AppTitle "Rendering Picture..." Graphics 640,480,32,2 SetBuffer BackBuffer() Dim colors(640,480,3) Dim Rave(160,240) Dim Gave(160,240) Dim Bave(160,240) picture=LoadImage("D:\Programming\Paintings\painting0.png") ;It won't even work with the full path to the picture, the program is in the same folder DrawImage picture,0,0 For y=0 To 479 For x=0 to 639 GetColor x,y colors(x,y,0)=ColorRed() colors(x,y,1)=ColorGreen() colors(x,y,2)=ColorBlue() Next Next For y=0 To 479 Step 4 For x=0 To 639 Step 4 Rave(x/4,y/4)=(colors(x,y,0)+colors(x+4,y,0)+colors(x,y+4,0)+colors(x+4,y+4,0))/4 Gave(x/4,y/4)=(colors(x,y,1)+colors(x+4,y,1)+colors(x,y+4,1)+colors(x+4,y+4,1))/4 Bave(x/4,y/4)=(colors(x,y,2)+colors(x+4,y,2)+colors(x,y+4,2)+colors(x+4,y+4,2))/4 DebugLog "R: " + Rave(x/4,y/4) + "---G: " + Gave(x/4,y/4) + "---B : " + Bave(x/4,y/4) ;For testing the code up to this point Next Next Flip |
| ||
@_PJ_>>the title of the thread is "Invalid Image Handle" so i assumed this was the error he/she had... |
| ||
Well I figured out that if I tried the code in Blitz 3D it runs perfectly. @_PJ_ Idk how you got the code to return 0 to every ColorRed(), ColorGreen() and ColorBlue() statement but that doesn't happen to me. |
| ||
|
| ||
Yep it can, and personally, I would never use anything other than a png, jpeg or a gif |
| ||
@_PJ_ Idk how you got the code to return 0 to every ColorRed(), ColorGreen() and ColorBlue() statement but that doesn't happen to me. Sorry, I think I was confusing with ReadPixel. If the code fails on BlitzPlus but works on Blitz3D (which is strange that you are referring to blitzplus issues in the Blitz3D discussion) - then it would seem to indicate the error is with the manner in which image data is stored. Blitz3D uses driectdraw surfaces for images, whilst Blitz+ either uses the given graphics engine format or holds the image in RAM by default I think it's as scratch. To get the code to run in Blitzplus, use SetGfxDriver and also declare the correct type of storage as the second parameter in the LoadImage line. |
| ||
I ran both of the sample programs in Blitz 3D- the original works fine and so does PJ's version...both wrote the data to the debug log. I have been specifying exact full paths to images,models and other files in Blitz 3d for quite a while- had difficulties otherwise. |
| ||
had difficulties otherwise. It's good to ensure the correct path. Obviously, on ends-user machines the paths will not necessarily be the same. This is best solved either by prefixing with a correct directory path determined from SystemProperty("AppDir") or specified environment variables, possibly in combination with accurate use of ChangeDir() and CurrentDir() |