当设置为 LWUIT 表单的背景图像时,PNG 图像被严重染色
我想制作一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LWUIT 默认使用背景图像缩放。它总是会缩放图像,除非您明确要求样式进行不同的行为,例如平铺、对齐等。尝试:
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:
验证从文件中读取的图像(即
sourceImage
)是否与本机手机设备中看到的一样。如果不是这样,问题就出在这里。如果您能够正确地看到
sourceImage
,那么在获取缩放图像时需要评估一些事情。如果您的表单 contentPane 的宽度/高度小于图像宽度/高度,则可以使用更好的选项
图像缩略图 = image.scaledSmallerRatio(this.getWidth(), this.getHeight());
注意:是的,它是 getWidth() 而不是 getPreferredW()。如果您没有获得所需的结果,请尝试使用 getPreferredW() 进行缩放。
如果您的图像的宽度/高度小于表单 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.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().
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.