please smbdy tell me how to get the real size of image (png for ex.) in pixels. I put it in object with DisplayNewImageRect and i want to save the proportion. There are many pics, which dynamicly apear and they have dif. proportion [import]uid: 166826 topic_id: 29574 reply_id: 329574[/import]
You can’t really use display.newImageRect() for this because you have to pass it the width and height. What you can do is use display.newImage() instead. It doesn’t take those parameters and will load the full sized image. Once it’s loaded, you can get the width and height values using obj.height and obj.weight (assuming your image was loaded into the “obj” object). Then you can use the :scale() method to resize it to fit your space.
obj = display.newImage("images/myphoto.jpg")
-- make it fit into a 300 px high area don't care how wide it is
scale = 300 / obj.height
obj:scale(scale,scale)
-- make it fit into a 300px wide area, don't care how high it is
scale = 300 / obj.width
obj:scale(scale,scale)
-- make it fit into a 300px wide box
scale = 300 / obj.height
newWidth = obj.width \* scale
if newWidth \> 300 then
scale = 300 / obj.width
end
obj:scale(scale,scale)
[import]uid: 19626 topic_id: 29574 reply_id: 118750[/import]
Thanks rob. It worked with mine. [import]uid: 166336 topic_id: 29574 reply_id: 119187[/import]
Great thanks) It help me) [import]uid: 166826 topic_id: 29574 reply_id: 119466[/import]