Note: You must be registered in order to post a reply.
|
Threshold |
Posted - May 13 2005 : 3:32:55 PM I need to find the width and height of various image file formats, including BMP, PNG, JPG, and GIF. I have found some useful information on http://www.wotsit.org/. However, PNG has evaded me.
I do have "working" but slow methods for finding out JPG and GIF, and BMP is quite simple [byte offset of 18 (location 19) for width [LONG] and height [also LONG] immediately follows].
For PNG, though, I can't find anything that tells me simply where in the file to find dimensions.
If you know a method of finding PNG dimensions please let me know, and/or if you have any efficient methods of getting the dimensions of GIF and JPG I would greatly appreciate to share the knowledge.
I'm using it for DirectX8 texture coordinates. You'd think D3DTexture8 would have some way of giving the image dimensions to you since it has to find them itself anyway! As far as I've seen, it doesn't.
EDIT: Eric, the "automatic URL to link" feature accidentally included the period at the end of my sentence in the URL. |
Eric Coleman |
Posted - May 21 2005 : 7:32:57 PM The signed vs unsigned really doesn't matter. It's still 32 bits of data. As as long as you know that VB treats a LONG as being signed means you can compensate. When reading the data from the disk, you read the 4 bytes into a long and if it's a negative number you know that you have a really large image.
To get the "unsigned" value from a Long, use the following code.
Function ConvULtoD(ByVal L As Long) As Double Const n = &H80000000 If L > 0 Then ConvULtoD = L: Exit Function L = L Or n Xor n ConvULtoD = CDbl(L) - n End Function
|
sdw |
Posted - May 21 2005 : 2:21:03 PM According to http://www.developerfusion.com/show/32/ VB longs are 32 bits signed, ranging from -2,147,483,648 to 2,147,483,647. I could have sworn I read Longs ranged from 0 to 65536. Looks like you win :\
quote: The values are unsigned 32 bit integers (LONG in VB).
But I still object to the unsigned bit of it >:) So does that mean you need to do some bit shifting to acquire the correct dimensions? |
Threshold |
Posted - May 21 2005 : 1:59:24 PM As far as I know, VB Longs are 32 bit (4 bytes, a.k.a. double word (dword)) signed integers. So basically, with other languages that have 32 bit unsigned primitive data types, you could get a much larger positive integer in the saved data type than could a VB Long. But it would be limited to positive integers only whereas the VB Long is capable of positive and negative integers alike.
Please correct me if I'm wrong. |
sdw |
Posted - May 21 2005 : 1:44:58 PM quote: The values are unsigned 32 bit integers (LONG in VB).
Are VB longs not 16 bit unsigned integers? |
Eric Coleman |
Posted - May 14 2005 : 10:39:49 AM PNG width and height should be offset by 12 bytes. 8 bytes for the PNG file format header, and then 4 more bytes for the IHDR chunk. Then Width is 4 bytes and then Height is 4 bytes. The values are unsigned 32 bit integers (LONG in VB). Source |
Threshold |
Posted - May 13 2005 : 11:35:45 PM Indeed it works. Simply pass a D3DXIMAGE_INFO variable to the srcInfo argument of the D3DDevice8.CreateTextureFromFileEx method and read the width and height (and depth) from that.
I'm still open to any information regarding a direct method for this in the case that someone does not want to load the graphic to find its dimensions. |
Threshold |
Posted - May 13 2005 : 4:03:41 PM I just found some information in the SDK hinting that one of the arguments in the CreateTextureFromFileEx method returns a D3DXIMAGE_INFO structure with a bunch of useful file information in it. I'll test it and get back to you guys. |
|
|
VBGamer |
© |
|
|
|
|