Example usage for java.awt.image BufferedImage TYPE_INT_RGB

List of usage examples for java.awt.image BufferedImage TYPE_INT_RGB

Introduction

In this page you can find the example usage for java.awt.image BufferedImage TYPE_INT_RGB.

Prototype

int TYPE_INT_RGB

To view the source code for java.awt.image BufferedImage TYPE_INT_RGB.

Click Source Link

Document

Represents an image with 8-bit RGB color components packed into integer pixels.

Usage

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

/**
 * Get the context locator./*  w  w w  .  j a va2  s.c om*/
 * @return the context locator.
 */
@Override
public String getLocator() {
    try {
        Properties locator = new Properties();
        locator.setProperty(BaseHandler.HANDLER_CLASS, getClass().getName());
        locator.setProperty(BaseHandler.HANDLER_SCOPE, JConsoleHandler.CONSOLE_SCOPE);
        locator.setProperty(JContext.CONTEXT_TYPE, getType());
        locator.setProperty(Locator.LOCATOR_TITLE, getTitle());
        if (entityLabel$ != null) {
            locator.setProperty(EntityHandler.ENTITY_LABEL, entityLabel$);
        }
        if (entityKey$ != null)
            locator.setProperty(EntityHandler.ENTITY_KEY, entityKey$);
        if (entihome$ != null)
            locator.setProperty(Entigrator.ENTIHOME, entihome$);
        if (webLinkKey$ != null)
            locator.setProperty(JWeblinksPanel.WEB_LINK_KEY, webLinkKey$);
        String icon$ = null;
        try {
            Icon icon = iconIcon.getIcon();
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage out = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), type);
            Graphics2D g2 = out.createGraphics();
            icon.paintIcon(new JPanel(), out.getGraphics(), 0, 0);
            g2.dispose();
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            ImageIO.write(out, "png", b);
            b.close();
            byte[] ba = b.toByteArray();
            icon$ = Base64.encodeBase64String(ba);
        } catch (Exception ee) {
        }
        if (icon$ == null)
            icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "edit.png");
        locator.setProperty(Locator.LOCATOR_ICON, icon$);
        return Locator.toString(locator);
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
        return null;
    }

}

From source file:com.enonic.vertical.adminweb.handlers.xmlbuilders.ContentEnhancedImageXMLBuilder.java

private int getBufferedImageType(String encodeType) {
    if (encodeType.equals("png")) {
        return BufferedImage.TYPE_INT_ARGB;
    } else {//from w  ww  .  j a v  a 2 s .  c om
        return BufferedImage.TYPE_INT_RGB;
    }
}

From source file:org.deegree.graphics.charts.ChartsBuilder.java

/**
 * Maps the image format to an appropriate type, either RGB or RGBA (allow opacity). There are image types that
 * allow opacity like png, while others don't, like jpg
 *
 * @param imgFormat/*w  ww.jav a  2s  .  c o  m*/
 * @return BufferedImage Type INT_ARGB if the mime type is image/png or image/gif INT_RGB else.
 */
protected int mapImageformat(String imgFormat) {
    if (("image/png").equals(imgFormat) || ("image/gif").equals(imgFormat)) {
        return BufferedImage.TYPE_INT_ARGB;
    }
    return BufferedImage.TYPE_INT_RGB;
}

From source file:Human1.java

private BufferedImage doRender(int width, int height) {

    BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage);
    //buffer.setYUp(true);

    setOffScreenBuffer(buffer);//from w w  w . j ava2 s .  co m
    renderOffScreenBuffer();
    waitForOffScreenRendering();
    bImage = getOffScreenBuffer().getImage();
    return bImage;
}

From source file:org.nekorp.workflow.desktop.servicio.reporte.orden.servicio.OrdenServicioDataFactory.java

private String generaImagenCombustible(double porcentaje) {
    try {/*from ww  w .  ja v  a2 s.c  o m*/
        int width = 186 * 3;
        int height = 15 * 3;
        IndicadorBarraGraphicsView view = new IndicadorBarraGraphicsView();
        view.setWidthBar(width);
        view.setHeightBar(height);
        view.setPorcentaje(porcentaje);
        BufferedImage off_Image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = off_Image.createGraphics();
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, width, height);
        view.paint(g2);
        File file = new File("data/nivelCombustible.jpg");
        saveJPG(off_Image, file);
        return file.getCanonicalPath();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static BufferedImage getBufferedImage(ICanvas<?>... canvas) {
    int width = Math.max(Stream.of(canvas).mapToInt(c -> c.getCanvasSize().width).sum(), 1);
    int height = Stream.of(canvas).mapToInt(c -> c.getCanvasSize().height).max().orElse(1);
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    int x = 0;//from w  w w.j av  a2 s .c  om

    for (ICanvas<?> c : canvas) {
        VisualizationImageServer<?, ?> server = c.getVisualizationServer(false);

        g.translate(x, 0);
        server.paint(g);
        x += c.getCanvasSize().width;
    }

    return img;
}

From source file:me.solhub.simple.engine.DebugLocationsStructure.java

@Override
protected void draw() {
    Graphics2D g = (Graphics2D) getGraphics();
    Graphics2D bbg = (Graphics2D) _backBuffer.getGraphics();

    //anti-aliasing code
    //        bbg.setRenderingHint(
    //                RenderingHints.KEY_TEXT_ANTIALIASING,
    //                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    //        bbg.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

    bbg.setColor(Color.WHITE);// w ww.j  a v  a 2  s .  co  m
    bbg.fillRect(0, 0, _windowWidth, _windowHeight);

    bbg.translate(_xOffset, _yOffset);

    // draw destinations
    bbg.setColor(_simState.startingDestination.getColor());
    bbg.drawOval(-(int) _simState.startingDestination.getRadius(),
            -(int) _simState.startingDestination.getRadius(),
            (int) _simState.startingDestination.getRadius() * 2,
            (int) _simState.startingDestination.getRadius() * 2);
    Iterator<Entry<Vector2D, Color>> blah = _destinationColors.entrySet().iterator();
    double destinationRadius = _simState.getDestinationRadius();
    while (blah.hasNext()) {
        Entry<Vector2D, Color> temp = blah.next();
        bbg.setColor(temp.getValue());
        //calculate center coordinate
        int x = (int) (temp.getKey().getX() - (destinationRadius));
        int y = (int) (temp.getKey().getY() - (destinationRadius));
        //drawOval draws a circle inside a rectangle
        bbg.drawOval(x, y, _simState.getDestinationRadius() * 2, _simState.getDestinationRadius() * 2);
    }

    // draw each of the agents
    Iterator<Agent> agentIter = _simState.getAgentIterator();
    while (agentIter.hasNext()) {
        Agent temp = agentIter.next();
        if (temp.isAlive()) {
            // decide whether to color for destination or group
            //                if( isDestinationColors )
            //                {
            //                    // if stopped then blink white and destination color
            //                    if( temp.hasReachedDestination() )
            //                    {
            //                        if( pulseWhite % 20 == 0 )
            //                        {
            //                            bbg.setColor( Color.WHITE );
            //                        }
            //                        else
            //                        {
            //                            bbg.setColor( temp.getDestinationColor() );
            //                        }
            //                    }
            //                    else
            //                    {
            //                        bbg.setColor( temp.getDestinationColor() );
            //                    }
            //                }
            //                else
            //                {
            //                    // if stopped then blink black and white
            //                    if( temp.hasReachedDestination() )
            //                    {
            //                        if( pulseWhite % 20 == 0 )
            //                        {
            //                            bbg.setColor( Color.WHITE );
            //                        }
            //                        else
            //                        {
            //                            bbg.setColor( temp.getGroup().getGroupColor() );
            //                        }
            //                    }
            //                    //set color to red if cancelled and global and not multiple initiators
            //                    else if(temp.getCurrentDecision().getDecision().getDecisionType().equals(
            //                            DecisionType.CANCELLATION ) 
            //                            && _simState.getCommunicationType().equals( "global" )
            //                            && !Agent.canMultipleInitiate()
            //                            )
            //                    {
            //                        bbg.setColor( Color.RED );
            //                    }
            //                    else
            //                    {
            //                        bbg.setColor( temp.getGroup().getGroupColor() );
            //                    }
            //                }

            double dx = temp.getCurrentDestination().getX() - temp.getCurrentLocation().getX();
            double dy = temp.getCurrentDestination().getY() - temp.getCurrentLocation().getY();
            double heading = Math.atan2(dy, dx);
            Utils.drawDirectionalTriangle(bbg, heading - Math.PI / 2, temp.getCurrentLocation().getX(),
                    temp.getCurrentLocation().getY(), 7, temp.getPreferredDestination().getColor(),
                    temp.getGroup().getGroupColor());

            //                bbg.fillOval( (int) temp.getCurrentLocation().getX() - _agentSize,
            //                        (int) temp.getCurrentLocation().getY() - _agentSize , _agentSize * 2, _agentSize * 2 );
        }
    }
    pulseWhite++;
    bbg.setColor(Color.BLACK);
    // the total number of groups
    bbg.setFont(_infoFont);

    bbg.drawString("Run: " + (_simState.getCurrentSimulationRun() + 1), _fontXOffset, _fontYOffset);
    bbg.drawString("Time: " + _simState.getSimulationTime(), _fontXOffset, _fontYOffset + _fontSize);
    bbg.drawString("Delay: " + LIVE_DELAY, _fontXOffset, _fontYOffset + _fontSize * 2);

    if (_simState.getCommunicationType().equals("global") && !Agent.canMultipleInitiate()) {
        String initiatorName = "None";
        if (_initiatingAgent != null) {
            initiatorName = _initiatingAgent.getId().toString();
        }
        bbg.drawString("Init: " + initiatorName, _fontXOffset, _fontYOffset + _fontSize * 3);
        bbg.drawString("Followers: " + _numberFollowing, _fontXOffset, _fontYOffset + _fontSize * 4);
    } else {
        bbg.drawString("Groups: " + _simState.getNumberGroups(), _fontXOffset, _fontYOffset + _fontSize * 3);
        bbg.drawString("Reached: " + _simState.numReachedDestination, _fontXOffset,
                _fontYOffset + _fontSize * 4);
        bbg.drawString("Inits: " + _simState.numInitiating, _fontXOffset, _fontYOffset + _fontSize * 5);
        bbg.drawString("Eaten: " + _simState.getPredator().getTotalAgentsEaten(), _fontXOffset,
                _fontYOffset + _fontSize * 6);
    }

    g.scale(_zoom, _zoom);
    g.drawImage(_backBuffer, 0, 0, this);
    if (SHOULD_VIDEO) {

        // setup to save to a png
        BufferedImage buff = new BufferedImage(_windowWidth, _windowHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D temp = (Graphics2D) buff.getGraphics();
        temp.scale(8, 4);
        temp.drawImage(_backBuffer, 0, 0, this);
        // sub-directory
        File dir = new File("video");
        dir.mkdir();
        // format string for filename
        String filename = String.format("video/run-%03d-time-%05d.png", _simState.getCurrentSimulationRun(),
                _simState.getSimulationTime());
        File outputfile = new File(filename);
        // save it
        try {
            ImageIO.write(buff, "png", outputfile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.lizardtech.expresszip.model.Job.java

private void exportTile(TileExport t, String jobName, String format, int counter) throws Exception {

    if (shutdown)
        throw new RuntimeException("Cancelled");

    ReferencedEnvelope tileBounds = null;
    Rectangle imageBounds = null;

    double minx = Math.min(t.bounds.getLeft(), t.bounds.getRight());
    double maxx = Math.max(t.bounds.getLeft(), t.bounds.getRight());
    double miny = Math.min(t.bounds.getTop(), t.bounds.getBottom());
    double maxy = Math.max(t.bounds.getTop(), t.bounds.getBottom());
    logger.info(String.format("Adding tile %d x: %f - %f, y: %f - %f", counter, minx, maxx, miny, maxy));
    if (jobParams.isProjectedCRS(CRS.decode(jobParams.getMapProjection()))) {
        tileBounds = new ReferencedEnvelope(t.bounds.getLeft(), t.bounds.getRight(), t.bounds.getTop(),
                t.bounds.getBottom(), CRS.decode(jobParams.getMapProjection()));

    } else {//from   w  ww .jav  a  2s.  c o  m
        tileBounds = new ReferencedEnvelope(minx, maxx, miny, maxy, CRS.decode(jobParams.getMapProjection()));
    }

    // Set view point on map
    MapViewport viewport = new MapViewport(tileBounds);
    viewport.setCoordinateReferenceSystem(CRS.decode(jobParams.getMapProjection()));

    // Create the bound for the image
    imageBounds = new Rectangle(0, 0, t.width, t.height);

    // Set up an ImageBuffer to write image to
    logger.info(
            String.format("Allocating BufferedImage of size %d x %d", imageBounds.width, imageBounds.height));
    int bufferType = BufferedImage.TYPE_INT_RGB;
    if (extensions.valueOf(format) == extensions.png)
        bufferType = BufferedImage.TYPE_INT_ARGB;

    BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, bufferType);
    Graphics2D graphics = image.createGraphics();

    // Render the unclipped image
    MapContent map = new MapContent();
    map.setViewport(viewport);

    WebMapServer wms = new WebMapServer(MapModel.getPrivateServerURL(), getWMSTimeOut());
    WMSLayer wmsLayer = null;
    for (ExpressZipLayer l : jobParams.getEnabledLayers()) {
        if (l instanceof RasterLayer && l.projectionIsSupported(jobParams.getMapProjection())) {
            if (wmsLayer == null)
                wmsLayer = new WMSLayer(wms, l.getGeoToolsLayer());
            else
                wmsLayer.addLayer(l.getGeoToolsLayer());
        }
    }
    if (wmsLayer != null)
        map.addLayer(wmsLayer);

    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(map);
    renderer.addRenderListener(new RenderListener() {

        @Override
        public void featureRenderer(SimpleFeature feature) {
        }

        @Override
        public void errorOccurred(Exception e) {
            logger.error("Streaming Renderer for tile failed (" + e.getMessage() + ")");
            throw new RuntimeException(e);
        }
    });

    try {
        renderer.paint(graphics, imageBounds, tileBounds);
    } finally {

        try {
            // clean up
            graphics.dispose();
        } catch (Exception e) {
        }

        try {
            map.dispose();
        } catch (Exception e) {
        }
    }

    // Clip the image to the shapefile
    if (cropFile != null) {
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = getFeatureSource(cropFile);
        GridCoverage2D clippedCoverage = (GridCoverage2D) clipImageToFeatureSource(image, tileBounds,
                featureSource);
        if (null == clippedCoverage) {
            logger.info("Tile does not intersect shapefile. Skipping.");
            return;
        }
        BufferedImage matted = mattCroppedImage(image, clippedCoverage, bufferType);
        image = matted;
    }

    // Save the image
    String fileBase = "";
    File fileToSave = null;
    try {
        do {
            fileBase = jobName;
            if (counter > 0)
                fileBase = fileBase + "_" + counter;
            fileToSave = new File(exportDir, fileBase + "." + format);
            counter++;
        } while (!fileToSave.createNewFile());

        logger.info(String.format("Writing image %s", fileToSave.getAbsolutePath()));

        GridCoverageFactory factory = new GridCoverageFactory();
        GridCoverage2D coverage = factory.create("LT", image, tileBounds);
        AbstractGridCoverageWriter coverageWriter = null;
        GeneralParameterValue[] formatParam = null;
        if (format.equals(extensions.tif.toString())) {
            ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
            params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString())
                    .setValue(geoTiffWPs);
            coverageWriter = new GeoTiffWriter(fileToSave);
            formatParam = (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1]);
        } else {
            ParameterValueGroup params = new WorldImageFormat().getWriteParameters();
            params.parameter(WorldImageFormat.FORMAT.getName().toString()).setValue(format);
            formatParam = new GeneralParameterValue[] {
                    params.parameter(WorldImageFormat.FORMAT.getName().toString()) };
            coverageWriter = new WorldImageWriter(fileToSave);
        }
        try {
            coverageWriter.write(coverage, formatParam);
        } finally {
            try {
                coverageWriter.dispose();
            } catch (Exception e) {
            }

            try {
                coverage.dispose(true);
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        logger.error(
                String.format("FAILED writing image %s (%s)", fileToSave.getAbsolutePath(), e.getMessage()));
        throw new RuntimeException(e);
    }

    // Gather up fileBase.* (include world and prj filenames) for zip file
    for (File child : exportDir.listFiles()) {
        String childName = child.getName();
        String baseName = FilenameUtils.getBaseName(childName);
        if (child.isFile() && baseName.equals(fileBase)) {
            String extension = FilenameUtils.getExtension(childName);
            extension.toLowerCase();
            if (extension.length() == 4 && extension.endsWith("w")) {
                extension = extension.substring(0, 1) + extension.substring(2);
                File renamedChild = new File(exportDir, baseName + "." + extension);
                child.renameTo(renamedChild);
                child = renamedChild;
            }

            outputTiles.add(child.getName());
        }
    }
}

From source file:it.geosolutions.opensdi2.mvc.BaseFileManager.java

/**
 * Generate a image thumb//from w  w  w  .j  a  v a 2 s.c  om
 * 
 * @param toServeUp
 * @param thumbPath
 * @return
 * @throws IOException
 */
protected InputStream getImageThumb(File toServeUp, String thumbPath) throws IOException {
    BufferedImage image = ImageIO.read(toServeUp);
    ImageIcon img = new ImageIcon(
            new ImageIcon(image).getImage().getScaledInstance(THUMB_W, THUMB_H, Image.SCALE_FAST));
    BufferedImage bimage = new BufferedImage(THUMB_W, THUMB_H, BufferedImage.TYPE_INT_RGB);

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();
    g.drawImage(img.getImage(), 0, 0, null);
    g.dispose();
    ImageIO.write(bimage, "jpg", new File(thumbPath));
    return new java.io.FileInputStream(thumbPath);
}

From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java

private static Image createExtensionsChartImage(List<CdrGraphBean> extensions, String xAxisLabel,
        String yAxisLabel) {//from w w w .j  a  va 2  s. c  o m
    // Create a dataset...
    DefaultCategoryDataset data = new DefaultCategoryDataset();

    // Fill dataset with beans data
    for (CdrGraphBean extension : extensions) {
        data.setValue(extension.getCount(), extension.getKey(), extension.getKey());
    }

    // Create a chart with the dataset
    JFreeChart barChart = ChartFactory.createBarChart3D(EMPTY_TITLE, xAxisLabel, yAxisLabel, data,
            PlotOrientation.VERTICAL, true, true, true);
    barChart.setBackgroundPaint(Color.lightGray);
    barChart.getTitle().setPaint(Color.BLACK);
    CategoryPlot p = barChart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.red);

    // Create and return the image with the size specified in the XML design
    return barChart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null);
}