2016-03-26 83 views
3

我有一个GUI构建的应用程序,管理客户端的配置文件。当创建一个新的配置文件时,会拍摄一张照片。路径(字符串)与其他信息一起保存在散列表中。Codename One - 从大图像创建小图像(并存储它)

当它显示所有客户端的列表时,每个客户端信息都设置为一个Multibutton,每个客户端信息都包含客户端的一个小图片。该图片是每次载入表单时都会设置的蒙版图片,因此载入速度非常缓慢(当我没有小图片时,载入速度更快)。

enter image description here

问题

我想保存蒙面小图片之后我拿&保存客户端的图片。所以当我显示客户端列表时,我只需要获取小图片,而不必为所有项目进行遮罩。这可能吗?

我想这样的:(我的目标是有一个工作“smallPhotoPath”)

String bigPhotoPath = Capture.capturePhoto(width, -1); 
Image bigPhoto = Image.createImage(bigPhotoPath); 
... 
//masking image 
... 
bigPhoto = bigPhoto.applyMask(mask); 

String smallPhotoPath = bigPhotoPath+"Small"; 
Image smallPhoto = bigPhoto.scaled(bigPhoto.getWidth()/8, -1); 
java.io.OutputStream os = Storage.getInstance().createOutputStream(smallPhotoPath); 
ImageIO.getImageIO().save(smallPhoto, os, ImageIO.FORMAT_PNG, 1); 
os.close(); 
+0

我不明白什么是不是在您的代码段的工作?注意,如果图像是预先屏蔽的,您需要从标签/多按钮中删除遮罩。 –

+0

当我稍后尝试使用“Image.createImage(smallPhotoPath)”为了加载到Multibutton的小图片,它不起作用,并且错误被捕获 – Felipe

+0

Shai,是否有可能使用EncodedImage这个?我检查了你的ChatApp教程,但是在那里你用一个URLImage替换了EncodedImage。我能做同样的事吗?但是对于捕获的图像而不是来自网络的图像? – Felipe

回答

2

尝试了很多之后,我解决了这个问题。我改变了以下线路:

java.io.OutputStream os = Storage.getInstance().createOutputStream(smallPhotoPath); 

这一个:

OutputStream os = FileSystemStorage.getInstance().openOutputStream(smallPhotoPath); 

现在工作得很好:)