Page 2 of 2

Re: get the width and height of an image file .png

Posted: Sun Jul 08, 2012 5:30 pm
by jmburnod
Hi Klaus,
Yes. It is very useful to scale file .png in a constant rect
I have done a little function using the code of Richard:

Code: Select all

function GetWidthHeightPngFile pPathIm --
   put empty into rGetWidthHeightPngFile
   open file pPathIm for binary read
     read from file pPathIm for 24
     put it into tData
     close file pPathIm
     --
     if byte 13 to 16 of tData <> "IHDR" then -- "Invalid PNG format"
      return empty
      exit GetWidthHeightPngFile
     end if
     --
     local tWidth, tHeight
     put binaryDecode("MM", byte 17 to 24 of tData, tWidth, tHeight)\
         into tNumConvertedVals
     if tNumConvertedVals <> 2 then -- Couldn't decode binary data 
       return empty
      exit GetWidthHeightPngFile
     end if
   put tWidth & "," & tHeight into rGetWidthHeightPngFile
   return rGetWidthHeightPngFile
end GetWidthHeightPngFile
Best
Jean-Marc

Re: get the width and height of an image file .png

Posted: Sat Jan 26, 2013 11:01 pm
by Mag
Klaus wrote:Hi Jean-Marc,

yes :-)

Do this:

Code: Select all

...
## This is the trick:
lock screen
## :-)

import paint from file "your/file/here.png"
put the formattedwidth of last img into tWidth
put the formattedheight of last img into tHeight
delete last img
unlock screen
...
Look ma, no hands erm... display :D


Best

Klaus
Grea trick Klaus! Just used in a iOS project.

Re: get the width and height of an image file .png

Posted: Sat Jan 26, 2013 11:41 pm
by jmburnod
Hi Mag,
Yes you can use importpaint or set the filename to know the width and height of an image file
but reading the file is faster
For 1000 image files
importpaint way: 9532 milliseconds
reading file way: 64 milliseconds

Best
Jean-Marc

Re: get the width and height of an image file .png

Posted: Tue Jan 29, 2013 11:02 pm
by Mag
jmburnod wrote:Hi Mag,
Yes you can use importpaint or set the filename to know the width and height of an image file
but reading the file is faster
For 1000 image files
importpaint way: 9532 milliseconds
reading file way: 64 milliseconds

Best
Jean-Marc
Hi Jean-Marc,

I have a jpeg image not png so I can't use that trick if I correctly understand :-(

PS
In my previous post I wrote that there was a problem of crash, after some test I discover that was cused by the unlock screen statement (it was not paired with a lock screen) I think.

Re: get the width and height of an image file .png

Posted: Wed Jan 30, 2013 1:32 pm
by jmburnod
Hi Mag,
I have a jpeg image not png so I can't use that trick if I correctly understand
Yes that is only for png file, but I think that is also possible for jpeg, we have to study the jpeg structure file
Best regards
Jean-Marc