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();
}
}
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();
}
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();
}
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;
}
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();
}
Aggregations