Search in sources :

Example 1 with ColorExtractor

use of com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor in project android by JetBrains.

the class SimpleViewCreator method extractColor.

/**
   * Find the color in the provided image and return them in the provided callback.
   * The callback is called in a separate Thread
   *
   * @param image    The image to extract the color from
   * @param callback The callback to get the result of the color extraction
   */
protected void extractColor(@NotNull BufferedImage image, @NotNull ColorExtractor.ColorExtractorCallback callback) {
    final Rectangle realCropping = getMockup().getComputedCropping();
    final Rectangle selectionBounds = getSelectionBounds();
    final BufferedImage subimage = image.getSubimage(realCropping.x + selectionBounds.x, realCropping.y + selectionBounds.y, selectionBounds.width, selectionBounds.height);
    ColorExtractor colorExtractor = new DBSCANColorExtractor(subimage, DBSCANColorExtractor.DEFAULT_EPS, DBSCANColorExtractor.getMinClusterSize(subimage));
    colorExtractor.run(callback);
}
Also used : DBSCANColorExtractor(com.android.tools.idea.uibuilder.mockup.colorextractor.DBSCANColorExtractor) ColorExtractor(com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor) DBSCANColorExtractor(com.android.tools.idea.uibuilder.mockup.colorextractor.DBSCANColorExtractor) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ColorExtractor

use of com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor in project android by JetBrains.

the class ColorExtractorTool method initColorsComponents.

private void initColorsComponents() {
    myExtractButton.addActionListener(e -> {
        if (myExtractedColors != null) {
            myColors.removeAll();
        }
        if (!myIsExtractingColor) {
            ColorExtractor colorExtractor = new DBSCANColorExtractor(myMockup);
            myIsExtractingColor = true;
            colorExtractor.run(new ColorExtractor.ColorExtractorCallback() {

                @Override
                public void result(Collection<ExtractedColor> rgbColors) {
                    myProgressBar.setValue(100);
                    myExportButton.setEnabled(true);
                    myIsExtractingColor = false;
                    myExtractedColors = rgbColors;
                    for (ExtractedColor color : rgbColors) {
                        ColorPanel colorPanel = new ColorPanel(color);
                        colorPanel.addHoveredListener(ColorExtractorTool.this);
                        JPanel component = colorPanel.getComponent();
                        component.setMaximumSize(component.getPreferredSize());
                        myColors.add(component, 0);
                    }
                    myColors.revalidate();
                }

                @Override
                public void progress(int progress) {
                    myProgressBar.setValue(progress);
                }
            });
        }
    });
}
Also used : DBSCANColorExtractor(com.android.tools.idea.uibuilder.mockup.colorextractor.DBSCANColorExtractor) ExtractedColor(com.android.tools.idea.uibuilder.mockup.colorextractor.ExtractedColor) ColorExtractor(com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor) DBSCANColorExtractor(com.android.tools.idea.uibuilder.mockup.colorextractor.DBSCANColorExtractor)

Aggregations

ColorExtractor (com.android.tools.idea.uibuilder.mockup.colorextractor.ColorExtractor)2 DBSCANColorExtractor (com.android.tools.idea.uibuilder.mockup.colorextractor.DBSCANColorExtractor)2 ExtractedColor (com.android.tools.idea.uibuilder.mockup.colorextractor.ExtractedColor)1 BufferedImage (java.awt.image.BufferedImage)1