Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Finding Image Dimensions
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Threshold
Squire

USA
44 Posts

Posted - May 13 2005 :  3:32:55 PM  Show Profile  Reply with Quote
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.

Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun."

Edited by - Threshold on May 13 2005 3:40:34 PM

Threshold
Squire

USA
44 Posts

Posted - May 13 2005 :  4:03:41 PM  Show Profile  Reply with Quote
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.


Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun."
Go to Top of Page

Threshold
Squire

USA
44 Posts

Posted - May 13 2005 :  11:35:45 PM  Show Profile  Reply with Quote
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.

Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun."
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - May 14 2005 :  10:39:49 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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
Go to Top of Page

sdw
Warrior

USA
160 Posts

Posted - May 21 2005 :  1:44:58 PM  Show Profile  Visit sdw's Homepage  Click to see sdw's MSN Messenger address  Reply with Quote
quote:
The values are unsigned 32 bit integers (LONG in VB).

Are VB longs not 16 bit unsigned integers?
Go to Top of Page

Threshold
Squire

USA
44 Posts

Posted - May 21 2005 :  1:59:24 PM  Show Profile  Reply with Quote
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.

Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun."
Go to Top of Page

sdw
Warrior

USA
160 Posts

Posted - May 21 2005 :  2:21:03 PM  Show Profile  Visit sdw's Homepage  Click to see sdw's MSN Messenger address  Reply with Quote
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?

Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - May 21 2005 :  7:32:57 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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
  
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.14 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.