我尝试将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(); 发布于 2017-04-08 01:02:50
以这种方式扩展URLImage是有问题的,因为在完成下载之前,URLImage的“数据”将是它的占位符图像。因此,调用像EncodedImage.createFromImage(urlimg, false)这样的东西只会将the图像的占位符图像创建为编码图像。
最好在加载URLImage之前获取占位符图像的正确大小,并在调用createToStorage()时使用适当的"scale“参数,以便图像正确映射到占位符尺寸。
https://stackoverflow.com/questions/43276796
复制相似问题