Click here to Skip to main content
16,011,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralFinding the dimensions of a PNG File Pin
Real World8-May-03 4:42
Real World8-May-03 4:42 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 4:58
David Crow8-May-03 4:58 
GeneralRe: Finding the dimensions of a PNG File Pin
Real World8-May-03 7:24
Real World8-May-03 7:24 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 7:33
David Crow8-May-03 7:33 
GeneralRe: Finding the dimensions of a PNG File Pin
Real World8-May-03 7:40
Real World8-May-03 7:40 
GeneralRe: Finding the dimensions of a PNG File Pin
Real World8-May-03 7:56
Real World8-May-03 7:56 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 9:09
David Crow8-May-03 9:09 
GeneralRe: Finding the dimensions of a PNG File Pin
David Crow8-May-03 10:22
David Crow8-May-03 10:22 
This should work:

// here's the bit-shifting stuff!
#define SH(p) ((unsigned short)(unsigned char)((p)[1]) | ((unsigned short)(unsigned char)((p)[0]) << 8))
#define LG(p) ((unsigned long)(SH((p)+2)) | ((unsigned long)(SH(p)) << 16))

void main( int argc, char *argv[] )
{
FILE *pFile;
unsigned char uBuffer[1024];
long lWidth,
lHeight,
lSize;


pFile = fopen(argv[1], "rb");
if (NULL != pFile)
{
fread(uBuffer, sizeof(unsigned char), 8, pFile);

fread(uBuffer, sizeof(unsigned char), 4, pFile);

// convert this to a long
lSize = (uBuffer[0] & 0xff);
lSize <<= 8;
lSize |= (uBuffer[1] & 0xff);
lSize <<= 8;
lSize |= (uBuffer[2] & 0xff);
lSize <<= 8;
lSize |= (uBuffer[3] & 0xff);

fread(uBuffer, sizeof(unsigned char), 4, pFile);

fread(uBuffer, sizeof(unsigned char), lSize, pFile);

lWidth = LG(uBuffer);
lHeight = LG(uBuffer + 4);

fclose(pFile);
}
}
GeneralI hate __int64! Pin
Simon Steele8-May-03 3:43
Simon Steele8-May-03 3:43 
GeneralRe: I hate __int64! Pin
David Crow8-May-03 4:08
David Crow8-May-03 4:08 
GeneralRe: I hate __int64! Pin
Len Holgate8-May-03 4:26
Len Holgate8-May-03 4:26 
GeneralRe: I hate __int64! Pin
Simon Steele8-May-03 4:41
Simon Steele8-May-03 4:41 
Generalfile properties Pin
urid8-May-03 3:32
urid8-May-03 3:32 
GeneralRe: file properties Pin
JensB8-May-03 3:44
JensB8-May-03 3:44 
GeneralRe: file properties Pin
David Crow8-May-03 4:10
David Crow8-May-03 4:10 
GeneralRe: file properties Pin
urid8-May-03 4:24
urid8-May-03 4:24 
GeneralRe: file properties Pin
David Crow8-May-03 3:52
David Crow8-May-03 3:52 
GeneralRe: file properties Pin
urid8-May-03 4:15
urid8-May-03 4:15 
GeneralRe: file properties Pin
David Crow8-May-03 4:43
David Crow8-May-03 4:43 
Generalcenter text in title bar of app. Pin
JensB8-May-03 3:04
JensB8-May-03 3:04 
GeneralRe: center text in title bar of app. Pin
David Crow8-May-03 4:25
David Crow8-May-03 4:25 
GeneralRe: center text in title bar of app. Pin
JensB8-May-03 4:30
JensB8-May-03 4:30 
GeneralRe: center text in title bar of app. Pin
Renjith Ramachandran8-May-03 5:14
Renjith Ramachandran8-May-03 5:14 
GeneralRe: center text in title bar of app. Pin
User 66588-May-03 6:17
User 66588-May-03 6:17 
GeneralRe: center text in title bar of app. Pin
Joan M8-May-03 5:57
professionalJoan M8-May-03 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.