1
我試圖將URLImage轉換爲EncodedImage來縮放它,但它將背景變成黑色。轉換工作正常,只有在縮放圖像時纔會出現此問題。在指南中說,URLImages有大小限制,但我不明白如何正確縮放它。如果有人可以寫一個關於如何將URLImage縮放到任意大小的示例,我將不勝感激。Codenameone規模URLImage
下面是我用
//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();