Java me PNG图像设置为LWUIT Form';背景图像

Java me PNG图像设置为LWUIT Form';背景图像,java-me,lwuit,lwuit-form,Java Me,Lwuit,Lwuit Form,我想制作一个png图像作为LWUIT表单的背景图像。问题是图像被改变了:在将图像设置为窗体的背景图像后,图像中有污点。以下是代码: public class DetailPhotoClient extends Form implements ActionListener { private Command options, delete, back, annuler, ok; private GaleriePhotos backForm; private FileCon

我想制作一个
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;
    }
    ...
}
我注意到,当我手动打开照片时,也就是从手机存储器的照片文件夹中打开照片时,照片不会被更改


因此,如何在将图像设置为窗体的背景图像时使其不被更改?

验证从文件读取的图像(即
sourceImage
)是否与本机电话设备中的图像相同。如果不是这样,问题就在这里

如果您能够看到
源图像
正确,那么在获取缩放图像时需要评估一些内容

  • 如果表单内容窗格的宽度/高度小于图像的宽度/高度,则使用更好的选项

    Image thumb=Image.scaledsmalerratio(this.getWidth(),this.getHeight())
    注意:是,它的getWidth()而不是getPreferredW()。如果没有得到所需的结果,请尝试使用getPreferredW()进行缩放

  • 如果图像的宽度/高度小于form contentPane的宽度/高度,则最好不要对其进行缩放,因为图像将适合屏幕


  • 默认情况下,LWUIT对背景图像使用缩放。它将始终缩放图像,除非您明确要求不同行为的样式,例如平铺、对齐等。请尝试:

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

    即使我使用
    scaledsmalerratio(this.getWidth(),this.getHeight()),图像也总是会被更改