LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Sun Jul 08, 2012 5:30 pm
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
https://alternatic.ch
-
Mag
- VIP Livecode Opensource Backer

- Posts: 802
- Joined: Fri Nov 16, 2012 10:51 pm
Post
by Mag » Sat Jan 26, 2013 11:01 pm
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
Best
Klaus
Grea trick Klaus! Just used in a iOS project.
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Sat Jan 26, 2013 11:41 pm
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
https://alternatic.ch
-
Mag
- VIP Livecode Opensource Backer

- Posts: 802
- Joined: Fri Nov 16, 2012 10:51 pm
Post
by Mag » Tue Jan 29, 2013 11:02 pm
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.
-
jmburnod
- VIP Livecode Opensource Backer

- Posts: 2729
- Joined: Sat Dec 22, 2007 5:35 pm
-
Contact:
Post
by jmburnod » Wed Jan 30, 2013 1:32 pm
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
https://alternatic.ch