【发布时间】:2017-04-08 01:02:50
【问题描述】:
我尝试将 URLImage 转换为 EncodedImage 以对其进行缩放,但它使背景变黑。转换工作正常,仅当我缩放图像时才会出现问题。在指南中它说 URLImages 有大小限制,但我不明白如何正确缩放它。如果有人可以写一个关于如何将 URLImages 缩放到任意大小的示例,我将不胜感激。
这是我使用的代码
//create the form
Form hi = new Form ("urlimage scaling");
try
{
//create placeholder image
EncodedImage placeholder = EncodedImage.create("/dog.jpg").scaledEncoded(492, 290);
//get image from the web
URLImage urlimg = URLImage.createToStorage(placeholder, "https://australianbananas.com.au/Images/Home/RipenessBlend.png",
"https://australianbananas.com.au/Images/Home/RipenessBlend.png");
//try to convert and scale
EncodedImage scaledImage = EncodedImage.createFromImage(urlimg,false).scaledEncoded(Display.getInstance().getDisplayWidth(), -1);
//display image using a label
Label lbl = new Label();
lbl.setIcon(scaledImage);
hi.add(lbl);
}
catch(Exception e) {System.out.println(""+e);}
hi.show();
【问题讨论】:
标签: codenameone