Finding a picture size ...
Blitz3D Forums/Blitz3D Programming/Finding a picture size ...
| ||
... before opening it with LoadImage() or LoadTexture() As described/confirmed in http://www.blitzbasic.com/Community/posts.php?topic=83088 what seems to be a Blitz3D/Plus bug causes a crash when trying to load a picture with the exact size of 580x819 pixels. So my question is "how can I check if a picture has that magic crash size if I cant load it ?" Knowing that : - Im making a tool to compare pictures, so it will encounter various file formats and sizes, - Im using freeimage to load gifs. I suppose that the crash wont happen with it, but its *far* slower than opening a picture with LoadImage(), so dont want use it for bmps, jpgs & pngs. - The tool is designed to be able to scan lots of picture (thousands), so the method to get the picture size should be quite fast. Im thinking about doing specific code to read the files headers of JPGs, BMPs & PNGs, but im not sure on how to do that or check that a picture labeled "something.jpg" is really a jpeg and not a misnamed picture. Any suggestions / code doing that ? |
| ||
I can't think of a way, without reading the header file tbh... |
| ||
I'm curious as to why you don't already know the size if the pictures you are comparing. |
| ||
Usually in the file header most image files have an 'id' or 'magic number' to confirm that it truly is a jpg/tif/tga/png etc, often in the first couple of bytes. I've written some code for reading in uncompressed TIFFs and TGAs - most file formats are easy enough to read if they're uncompressed or compressed with a fairly simple method like RLE. Also in the header they always contain a reference to the width and height and of an image along with lots of other information. Have a look on google under 'jpg file specification' or similar. Reading the header is usually pretty easy. |
| ||
Thanks Matty, I will search in this way. |
| ||
Try it: and use: If ImageInfo_ReadFile ( YourFile$ ) Then DebugLog "Width: "+ImageInfo_Width DebugLog "Height: "+ImageInfo_Height Else DebugLog "Can't read info" Endif |
| ||
Thanks alot MikhailV, this worked perfectly and saved me quite some time and headache. Thanks to you I was able to release beta 2 of my Dupes Peach Pan : ) (its on www.sirlondon.net). You're now featured in the readme credits :D |