Why works different with version 704 and 828

best people, i have a question, i want first resize the image, then change the canvas size of image(150x150),
my code:

[code]local demo_pic = display.newImage(“d.jpg”)

function resize( event )

local g = event.target

if g.width < g.height then
g:scale(150/g.width, 150/g.width)
g.height = g.width
elseif g.width > g.height then
g:scale(150/g.height, 150/g.height)
g.width = g.height
elseif g.width == g.height then
g:scale(150/g.height, 150/g.height)
g.width = g.height
end
end

demo_pic:addEventListener(“tap”, resize)[/code]
but works different, look:

that works nice with version 704, but not version 828, somebody know why? [import]uid: 38153 topic_id: 27366 reply_id: 327366[/import]

What are the symptoms? What is different between the two?

Isn’t .width and .height calculated based on the image size? Can you write to those variables? What is the expected behavior for changing the width and height directly (and not using scale())?

If setting width and height that way, wouldn’t your image end up square?

[import]uid: 19626 topic_id: 27366 reply_id: 111168[/import]

I have an attachment [import]uid: 38153 topic_id: 27366 reply_id: 111173[/import]

@Saco,
I think I understand what you mean.
The difference is that some version between 704 and 828 has changed the behavior of the image when its .width and .height are set.
In the older versions of Corona, setting these values explicitly could CROP the image, and this is what you see on the left. In the newer versions of Corona setting these values will STRETCH image.
I read about this in another forum post a few weeks ago.

So now if you want to crop image with Corona, the only way to do it is to use mask.
Hope this helps :slight_smile:
N
[import]uid: 80100 topic_id: 27366 reply_id: 111185[/import]

Thanks for the tips [import]uid: 38153 topic_id: 27366 reply_id: 111305[/import]

In build 704 changing the object.width or object.height would change the object’s dimension based on the center of the object. In effect, cropping the object from the sides or top and bottom. This behavior was never documented and the result of the way the graphics code was implemented.

In build 759 we fixed some issues in the openGL graphics rendering code which changed the behavior. Now setting the object.width or object.height changes the width or height of the object without cropping the object. The object is not stretched unless you only change one property or change both properties with non-proportional values. It’s now similar to scaling the object.

We are looking into adding an image cropping API in a future release. [import]uid: 7559 topic_id: 27366 reply_id: 111449[/import]

–> “We are looking into adding an image cropping API in a future release.”
+1000. :slight_smile:
[import]uid: 13859 topic_id: 27366 reply_id: 111896[/import]