I'm trying to get into XNA v1.0 (..last time I touched it was Beta 1.) ...So, I'm building myself a terrain loader. Trying to get my Terrain class set up so that it can be given a heightmap file and it can initialize the size of the data array based upon the width & height of the file that is passed to it. Does anyone know of a way(preferrably a simple way) of accepting the path of a jpeg and getting the width and height out of the FileInfo?(I'm making an assumption that is where it is located, but I do not know for a fact)
A JPEG file contains a lot of packets (with Hufman tables and everything).
The above code does not know much about JPEG, it simply tries to jump from one packet
to the next until it finds one with size info.
Actually not very long, I did not read most of the spec, I just looked for the overall
structure (packets with 2B code and 2B length field) and a couple of specifics that did
interest me at the time. And with a simple viewer, I just looked inside a lot of JPEG files
to see what kind of information typically gets included.
BTW a lot of cameras add exposure information (make and model, datetime, image corrections,
etc) to the JPEG files they create, and the Image class allows you to retrieve these
using the getPropertyItem() method.
...I was thinking that I was going to have to find a way to pull the FileHeader off, store it in the .Net equivalent of a BITMAPFILEHEADER. Then, pull the InfoHeader off of the file and store it in the .NET equivalent of a BITMAPINFOHEADER...& pull the width & height from it
...or by using WMI. That was more along my line of thinking.
I know that WMI is for system resources, but I saw an example while I was doing online research where somebody went to the WMI classes for the owner of a specific file (I think he went to one of the Operating System's Win32_Security classes) ...I was just thinking that the information might be included with it *somewhere*
right...I knew that the BITMAPINFOHEADER was for a bmp & not a jpg ...but I was hoping that something could be done to mimic its usage. (My bmp viewer is in C++...never ported it to .NET) ...bmp's are actually extremely simple, barely a step up from a PPM.
I'm sure you could find it yourself, but the header just looks like this:
bits per pixel field
important colors field
...then you just have to remember that bitmaps are encoded as BGR values instead of RGB, so you have to map them accordingly
no...identical code. Cut & pasted it. .NET's saying that it won't let a case fall through to execute code from another case. ...OxCF was the case that actually had code to execute. ..the others fell through to 0xCF.
yeah, I can live with it...I'm having a new problem though:
if (code != 0xFF) thrownew ApplicationException(
"Unexpected value in file " + filename);
throws ....code equaled 216. What exactly is that check for? Do you know what the value of 216 means in this context? The first pass through, "code" was 255, then the next value was ...[Fixed it before I finished the post]
...Since the only thing I'm wanting to do is determine the width & height of the file, I just place a check for them inside the code check so it's now looking for
so now it will only throw if the width & height haven't been set yet..if they've been set, then I simply break when the code is not 0xFF. ...Is 0xFF like a key value for the header or something like that?
the FF-check is for protection (I want the code to fail on something that isnt a
JPEG at all!); so far all valid packets have a two-byte code that looks like 0xFFXX,
and my code did return as soon as size was seen; you should not continue
scanning the file after that ! (typically the size info is in the first few % of the file,
and the scanner as is probably is unable to handle everything that might follow it).
If there is any more trouble, please publish the entire method again. If you think there
are some valid JPEG files that my code does not handle well, then mail me one or two of them.