【问题标题】:Codenameone scale URLImage代号规模 URLImage
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      相关资源
      最近更新 更多