首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codenameone scale URLImage

Codenameone scale URLImage
EN

Stack Overflow用户
提问于 2017-04-07 19:17:43
回答 1查看 44关注 0票数 1

我尝试将URLImage转换为EncodedImage以缩放它,但它将背景变为黑色。转换工作正常,只有当我缩放图像时才会出现问题。在指南中,它说URLImages有大小限制,但我不知道如何正确地扩展它。如果有人能写一个关于如何将URLImages扩展到任意大小的例子,我将非常感激。

下面是我使用的代码

代码语言:javascript
复制
    //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();   
EN

回答 1

Stack Overflow用户

发布于 2017-04-08 01:02:50

以这种方式扩展URLImage是有问题的,因为在完成下载之前,URLImage的“数据”将是它的占位符图像。因此,调用像EncodedImage.createFromImage(urlimg, false)这样的东西只会将the图像的占位符图像创建为编码图像。

最好在加载URLImage之前获取占位符图像的正确大小,并在调用createToStorage()时使用适当的"scale“参数,以便图像正确映射到占位符尺寸。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43276796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档