当设置为 LWUIT 表单的背景图像时,PNG 图像被严重染色

发布于 2024-12-17 19:45:41 字数 1591 浏览 1 评论 0原文

我想制作一个 png 图像作为 LWUIT 表单的背景图像。问题是图像被更改:将其设置为表单的背景图像后,图像中存在污点。以下是代码:

public class DetailPhotoClient extends Form implements ActionListener {

    private Command options, delete, back, annuler, ok;
    private GaleriePhotos backForm;
    private FileConnection fcFile;
    private Image sourceImage, fullImage;
    private InputStream is;
    private PopupMenu popup;

    public DetailPhotoClient(GaleriePhotos prevForm, String absolutePathphotoName)
    {
        super();
        back = new Command("Retour");
        options = new Command("Options");
        this.addCommand(back);
        this.addCommand(options);
        this.addCommandListener(this);

        delete = new Command("Supprimer");
        annuler = new Command("Annuler");
        ok = new Command("Ok");

        backForm = prevForm;

        try {
            fcFile = (FileConnection) Connector.open(absolutePathphotoName, Connector.READ);
            is = fcFile.openInputStream();
            sourceImage = Image.createImage(is);
            fullImage = createThumbnail(sourceImage);
            setBgImage(fullImage);
            is.close();
            fcFile.close();
        } catch (IOException ex) {
            handleException();
        } catch (OutOfMemoryError oom) {
            handleOOM();
        }
    }
    private Image createThumbnail(Image image) {
        Image thumb = image.scaled(this.getPreferredW(), this.getPreferredH());
        return thumb;
    }
    ...
}

我注意到当我手动打开照片时,即来自手机内存的照片文件夹中的照片,那么照片不会被更改!

那么如何让设置为Form背景图片时不改变图片呢?

I want to make a png Image as the background image of a LWUIT Form. The problem is that the image is altered : there are stains in the image after setting it as the Form's background image. Here are codes :

public class DetailPhotoClient extends Form implements ActionListener {

    private Command options, delete, back, annuler, ok;
    private GaleriePhotos backForm;
    private FileConnection fcFile;
    private Image sourceImage, fullImage;
    private InputStream is;
    private PopupMenu popup;

    public DetailPhotoClient(GaleriePhotos prevForm, String absolutePathphotoName)
    {
        super();
        back = new Command("Retour");
        options = new Command("Options");
        this.addCommand(back);
        this.addCommand(options);
        this.addCommandListener(this);

        delete = new Command("Supprimer");
        annuler = new Command("Annuler");
        ok = new Command("Ok");

        backForm = prevForm;

        try {
            fcFile = (FileConnection) Connector.open(absolutePathphotoName, Connector.READ);
            is = fcFile.openInputStream();
            sourceImage = Image.createImage(is);
            fullImage = createThumbnail(sourceImage);
            setBgImage(fullImage);
            is.close();
            fcFile.close();
        } catch (IOException ex) {
            handleException();
        } catch (OutOfMemoryError oom) {
            handleOOM();
        }
    }
    private Image createThumbnail(Image image) {
        Image thumb = image.scaled(this.getPreferredW(), this.getPreferredH());
        return thumb;
    }
    ...
}

I noticed that when I open the photo manually , that is from the phone memory's photo folder , then the photo is not altered !

So how to make the image not altered when setting it as the Form's background image ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

演多会厌 2024-12-24 19:45:41

LWUIT 默认使用背景图像缩放。它总是会缩放图像,除非您明确要求样式进行不同的行为,例如平铺、对齐等。尝试:

myForm.getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_ALIGNED_CENTER);

LWUIT uses scaling for background images by default. It will always scale the images unless you explicitly ask the style for different behavior e.g. tiling, aligning etc. try:

myForm.getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_ALIGNED_CENTER);
且行且努力 2024-12-24 19:45:41

验证从文件中读取的图像(即 sourceImage)是否与本机手机设备中看到的一样。如果不是这样,问题就出在这里。

如果您能够正确地看到 sourceImage,那么在获取缩放图像时需要评估一些事情。

  1. 如果您的表单 contentPane 的宽度/高度小于图像宽度/高度,则可以使用更好的选项

    图像缩略图 = image.scaledSmallerRatio(this.getWidth(), this.getHeight());
    注意:是的,它是 getWidth() 而不是 getPreferredW()。如果您没有获得所需的结果,请尝试使用 getPreferredW() 进行缩放。

  2. 如果您的图像的宽度/高度小于表单 contentPane 的宽度/高度,您最好不要缩放它,因为图像将适合屏幕。

Validate whether the image read from file, i.e. sourceImage, is as seen in the native phone device. If not so the problem lies here.

If you are able to see the sourceImage correct, than there are some things to be evaluated in getting a scaled image.

  1. In case your form contentPane's width / height is smaller than the images width / height than a better option would be use

    Image thumb = image.scaledSmallerRatio(this.getWidth(), this.getHeight());
    NOTE: Yes, its getWidth() and not getPreferredW(). If you don't get desired result than try scaling with getPreferredW().

  2. In case your image's width / height is smaller than form contentPane's width / height, you might as well do not scale it since the image will fit the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文