从相机中点击img(下面的代码),但问题是如何在gui渲染器的列表中显示它们。
@Override
protected void onListFromCamera_SaveImgAction(final Component c, ActionEvent event) {
Capture.capturePhoto(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
try {
if (evt == null) {
return;
}
String path = (String) evt.getSource();
if (ImageIO.getImageIO() != null) {
String photoName = "" + System.currentTimeMillis();
java.io.OutputStream os = Storage.getInstance().createOutputStream(photoName);
ImageIO.getImageIO().save(FileSystemStorage.getInstance().openInputStream(path), os, ImageIO.FORMAT_JPEG, 50, 50, 0.9f);
os.close();
Image img = Image.createImage(Storage.getInstance().createInputStream(photoName));
photo = photoName;
// ((Label)c).setIcon(img);
findLabelImg().setIcon(img);
c.getParent().getParent().animateLayout(400);
}
} catch (Exception e) {
}
}
});
}
//捕获的图像列在下面的listModel方法中...这是我遇到的问题
@Override
protected boolean initListModelCapturedList(final List cmp) {
cmp.setModel(new com.codename1.ui.list.DefaultListModel(new String[]{"Item 1", "Item 2", "Item 3"}));
final Button b = ((GenericListCellRenderer) cmp.getRenderer()).extractLastClickedComponent();
final Button mybtn = findBtncamera();
System.out.println("sdkfjdkfj" + b);
if (b != null && "btncamera".equals(b.getName())) {//btncamera is the name of the button in renderer
mybtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//do smth
showForm("Main", null);
}
});
答案 0 :(得分:0)
您可以查看本教程,了解捕获并添加到图像网格:https://www.udemy.com/build-mobile-ios-apps-in-java-using-codename-one/
它还使用ImageViewer
类来允许您通过图像滑动。