缩放encodedImage

时间:2016-02-21 06:09:32

标签: codenameone

我们如何根据宽度缩放encodedImage,高度只是按宽度比例缩放?我们可以scaleWidth图像,但没有scaledEncodedWidth。有没有办法根据宽度来缩放编码图像的宽度和高度尺?

代码:

homePlaceholder = (EncodedImage) r.getImage("placeholder.png");
homePlaceholder = homePlaceholder.scaledEncoded(screenWidth / 3, screenWidth / 3);
//the following doesnt work as well
homePlaceholder = homePlaceholder.scaledEncoded(screenWidth / 3, -1);

1 个答案:

答案 0 :(得分:1)

我希望用Image替换EncodedImage将解决您的问题,如下面的代码所示

Image homePlaceholder =(Image) r.getImage("placeholder.png");
homePlaceholder = homePlaceholder.scaledWidth(screenWidth / 3);

EncodedImage encodedHomePlaceholder =   EncodedImage.createFromImage(homePlaceholder , true)