示例#1
0
  private BufferedImage createPMCode() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    new Parser().write(panel.getModel(), bos);

    PMCodeEncoderJNI encoder = new PMCodeEncoderJNI();
    int ret = encoder.encode(bos.toByteArray(), encoder);
    if (ret != 0) {
      JOptionPane.showMessageDialog(FSFrame.this, "Error :" + ret);
      return null;
    }

    byte[] image = encoder.getImage();
    int width = encoder.getWidth();
    int height = encoder.getHeight();
    int[] rgbArray = new int[width * height];
    int index = 0;
    for (int rgb_index = 0; rgb_index < rgbArray.length; rgb_index++) {
      rgbArray[rgb_index] |= (image[index] << 16 & 0xFF0000);
      rgbArray[rgb_index] |= (image[index + 1] << 8 & 0x00FF00);
      rgbArray[rgb_index] |= (image[index + 2] & 0x0000FF);
      index = index + 3;
    }

    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    bi.setRGB(0, 0, width, height, rgbArray, 0, width);
    return bi;
  }
示例#2
0
  private void initGui() {
    panel.setLayerSelector(layerSelector);

    setTitle("Feel Sketch");

    setResizable(false);
    getContentPane().setLayout(new BorderLayout());

    this.setJMenuBar(menuBar);
    menuBar.add(fileMenu);
    menuBar.add(paletteMenu);

    fileMenu.add(newMenu);
    fileMenu.add(loadMenu);
    fileMenu.add(saveMenu);
    fileMenu.add(saveImageMenu);
    fileMenu.add(saveImagePmMenu);
    fileMenu.add(exportMenu);
    fileMenu.addSeparator();
    fileMenu.add(quitMenu);

    paletteMenu.add(selectMenu);
    paletteMenu.add(penMenu);
    paletteMenu.add(iconMenu);
    paletteMenu.add(eraserMenu);
    paletteMenu.add(bgMenu);
    paletteMenu.addSeparator();
    paletteMenu.add(pagePrefMenu);

    toolBar.setFloatable(false);

    toolBar.add(new NewAction());
    toolBar.add(new SaveAction());
    toolBar.add(new LoadAction());
    toolBar.add(new ExportAction());
    toolBar.add(Box.createHorizontalStrut(10));
    toolBar.add(new SelectAction());
    toolBar.add(new PenAction());
    toolBar.add(new EraserAction());
    toolBar.add(new IconAction());
    toolBar.add(new BGSelectAction());
    toolBar.add(Box.createHorizontalStrut(10));
    toolBar.add(new PagePrefAction());

    add(toolBar, BorderLayout.NORTH);
    add(layerSelector, BorderLayout.EAST);

    // panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));

    panel.addPropertyChangeListener(
        "preferredSize",
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            pack();
          }
        });

    JPanel basePanel = new JPanel();
    palette.setOwner(panel);
    basePanel.setLayout(new GridBagLayout());
    basePanel.add(
        palette,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(4, 4, 4, 4),
            0,
            0));
    basePanel.add(
        panel,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(4, 4, 4, 4),
            0,
            0));
    getContentPane().add(basePanel, BorderLayout.CENTER);

    palette.startPenMode();
  }