Search in sources :

Example 66 with BufferedImage

use of java.awt.image.BufferedImage in project binnavi by google.

the class CodeDisplay method updateVisibleLinesAndColumns.

void updateVisibleLinesAndColumns() {
    // Calculates how many lines and columns will be actually visible at the
    // moment.
    int currentVisibleLines = getNumberOfVisibleLines();
    int currentVisibleColumns = getNumberOfVisibleColumns();
    if ((currentlyVisibleLines != currentVisibleLines) || (currentlyVisibleColumns != currentVisibleColumns)) {
        currentlyVisibleLines = currentVisibleLines;
        currentlyVisibleColumns = currentVisibleColumns;
        // Include room for the newline characters.
        int properWidth = codeModel.getTotalWidthInCharacters();
        int properLines = currentlyVisibleLines + 1;
        charBuffer = new FormattedCharacterBuffer(properLines, properWidth);
        bufferedImage = new BufferedImage(properWidth * fontCharWidth, properLines * fontLineHeight, BufferedImage.TYPE_INT_RGB);
        bufferedGraphics = (Graphics2D) bufferedImage.getGraphics();
    }
}
Also used : Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage)

Example 67 with BufferedImage

use of java.awt.image.BufferedImage in project gephi by gephi.

the class StatisticsModelImpl method embedImages.

private String embedImages(String report) {
    StringBuilder builder = new StringBuilder();
    String[] result = report.split("file:");
    boolean first = true;
    for (int i = 0; i < result.length; i++) {
        if (result[i].contains("</IMG>")) {
            String next = result[i];
            String[] elements = next.split("\"");
            String filename = elements[0];
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            File file = new File(filename);
            try {
                BufferedImage image = ImageIO.read(file);
                ImageIO.write((RenderedImage) image, "PNG", out);
            } catch (Exception e) {
                e.printStackTrace();
            }
            byte[] imageBytes = out.toByteArray();
            String base64String = Base64.encodeBase64String(imageBytes);
            if (!first) {
                builder.append("\"");
            }
            first = false;
            builder.append("data:image/png;base64,");
            builder.append(base64String);
            for (int j = 1; j < elements.length; j++) {
                builder.append("\"");
                builder.append(elements[j]);
            }
        } else {
            builder.append(result[i]);
        }
    }
    return builder.toString();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 68 with BufferedImage

use of java.awt.image.BufferedImage in project qrcode by yanbe.

the class J2SEDebugCanvas method drawMatrix.

public void drawMatrix(boolean[][] matrix) {
    if (image == null) {
        image = new BufferedImage(matrix.length, matrix[0].length, BufferedImage.TYPE_INT_ARGB);
        setSize(matrix.length, matrix[0].length);
    }
    Graphics2D g2d = image.createGraphics();
    g2d.setColor(java.awt.Color.WHITE);
    int width = getWidth();
    for (int x = 0; x < matrix.length; x++) {
        g2d.drawLine(x, 0, x, width);
    }
    g2d.setColor(java.awt.Color.BLACK);
    for (int x = 0; x < matrix.length; x++) {
        for (int y = 0; y < matrix[0].length; y++) {
            if (matrix[x][y] == true)
                g2d.drawLine(x, y, x, y);
        }
    }
    repaint();
}
Also used : BufferedImage(java.awt.image.BufferedImage) Point(jp.sourceforge.qrcode.geom.Point) Graphics2D(java.awt.Graphics2D)

Example 69 with BufferedImage

use of java.awt.image.BufferedImage in project qrcode by yanbe.

the class J2SECanvas method processDecode.

static boolean processDecode(String filename, QRCodeDecoder decoder) {
    DebugCanvas canvas = new J2SECanvas();
    decoder.setCanvas(canvas);
    BufferedImage image = null;
    try {
        if (filename.startsWith("http://"))
            image = ImageIO.read(new URL(filename));
        else
            image = ImageIO.read(new File(filename));
        String decodedString = new String(decoder.decode(new J2SEImage(image)));
        decodedString = ContentConverter.convert(decodedString);
        System.out.println(decodedString);
    } catch (IOException e) {
        canvas.println("Error: " + e.getMessage() + " " + filename);
        return false;
    } catch (DecodingFailedException dfe) {
        canvas.println("Error: " + dfe.getMessage());
        return false;
    } catch (Exception e) {
        canvas.println("Error: " + e.getMessage());
        return false;
    }
    return true;
}
Also used : IOException(java.io.IOException) DebugCanvas(jp.sourceforge.qrcode.util.DebugCanvas) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) DecodingFailedException(jp.sourceforge.qrcode.exception.DecodingFailedException) IOException(java.io.IOException) InvalidVersionInfoException(jp.sourceforge.qrcode.exception.InvalidVersionInfoException) DecodingFailedException(jp.sourceforge.qrcode.exception.DecodingFailedException)

Example 70 with BufferedImage

use of java.awt.image.BufferedImage in project antlrworks by antlr.

the class XJTree method createDragImage.

public void createDragImage(DragGestureEvent event) {
    Point dragOrigin = event.getDragOrigin();
    TreePath path = getPathForLocation(dragOrigin.x, dragOrigin.y);
    Rectangle r = getPathBounds(path);
    dragImageOffset.setLocation(dragOrigin.x - r.x, dragOrigin.y - r.y);
    JLabel label = (JLabel) getCellRenderer().getTreeCellRendererComponent(this, path.getLastPathComponent(), false, isExpanded(path), getModel().isLeaf(path.getLastPathComponent()), 0, false);
    label.setSize(r.width, r.height);
    dragImage = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D g2d = dragImage.createGraphics();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f));
    label.paint(g2d);
    g2d.dispose();
}
Also used : TreePath(javax.swing.tree.TreePath) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1702 Graphics2D (java.awt.Graphics2D)376 IOException (java.io.IOException)220 File (java.io.File)195 FunctionException (lucee.runtime.exp.FunctionException)122 Graphics (java.awt.Graphics)104 ByteArrayOutputStream (java.io.ByteArrayOutputStream)89 Color (java.awt.Color)88 ByteArrayInputStream (java.io.ByteArrayInputStream)86 Test (org.junit.Test)81 WritableRaster (java.awt.image.WritableRaster)75 Point (java.awt.Point)71 Rectangle (java.awt.Rectangle)68 AffineTransform (java.awt.geom.AffineTransform)57 Image (java.awt.Image)56 InputStream (java.io.InputStream)51 Dimension (java.awt.Dimension)50 ImageIcon (javax.swing.ImageIcon)50 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)46 ImageWriter (javax.imageio.ImageWriter)45