use of java.awt.image.BufferedImage in project spring-security-oauth by spring-projects.
the class SparklrRedirectController method photo.
@RequestMapping("/sparklr/redirect/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id) throws Exception {
InputStream photo = sparklrService.loadSparklrPhoto(id);
if (photo == null) {
throw new UnavailableException("The requested photo does not exist");
}
BufferedImage body;
MediaType contentType = MediaType.IMAGE_JPEG;
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
ImageReader imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
body = imageReader.read(0, irp);
} else {
throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
use of java.awt.image.BufferedImage in project spring-security-oauth by spring-projects.
the class SparklrController method photo.
@RequestMapping("/sparklr/photos/{id}")
public ResponseEntity<BufferedImage> photo(@PathVariable String id) throws Exception {
InputStream photo = sparklrService.loadSparklrPhoto(id);
if (photo == null) {
throw new UnavailableException("The requested photo does not exist");
}
BufferedImage body;
MediaType contentType = MediaType.IMAGE_JPEG;
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
ImageReader imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
imageReader.setInput(new MemoryCacheImageInputStream(photo), true);
body = imageReader.read(0, irp);
} else {
throw new HttpMessageNotReadableException("Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<BufferedImage>(body, headers, HttpStatus.OK);
}
use of java.awt.image.BufferedImage in project gephi by gephi.
the class AbstractSparklinesGraphicsComponentProvider method setImagePainter.
public void setImagePainter(Object value, boolean isSelected) {
if (value == null) {
rendererLabel.setPainter(null);
return;
}
Number[][] values = getSparklinesXAndYNumbers(value);
Number[] xValues = values[0];
Number[] yValues = values[1];
//If there is less than 1 element, don't show anything.
if (yValues.length < 1) {
rendererLabel.setPainter(null);
return;
}
if (yValues.length == 1) {
//SparklineGraph needs at least 2 values, duplicate the only one we have to get a sparkline with a single line showing that the value does not change over time
xValues = null;
yValues = new Number[] { yValues[0], yValues[0] };
}
Color background;
if (isSelected) {
background = SELECTED_BACKGROUND;
} else {
background = UNSELECTED_BACKGROUND;
}
//Note: Can't use interactive SparklineComponent because TableCellEditors don't receive mouse events.
final SparklineParameters sparklineParameters = new SparklineParameters(rendererLabel.getWidth() - 1, rendererLabel.getHeight() - 1, Color.BLUE, background, Color.RED, Color.GREEN, null);
final BufferedImage image = SparklineGraph.draw(xValues, yValues, sparklineParameters);
rendererLabel.setPainter(new ImagePainter(image));
}
use of java.awt.image.BufferedImage in project gitblit by gitblit.
the class BranchGraphServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
InputStream is = null;
Repository r = null;
PlotWalk rw = null;
try {
String repository = request.getParameter("r");
if (StringUtils.isEmpty(repository)) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().append("Bad request");
return;
}
String objectId = request.getParameter("h");
String length = request.getParameter("l");
r = repositoryManager.getRepository(repository);
if (r == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().append("Bad request");
return;
}
rw = new PlotWalk(r);
if (StringUtils.isEmpty(objectId)) {
objectId = JGitUtils.getHEADRef(r);
}
ObjectId id = r.resolve(objectId);
if (id == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().append("Bad request");
return;
}
rw.markStart(rw.lookupCommit(id));
// default to the items-per-page setting, unless specified
int maxCommits = settings.getInteger(Keys.web.itemsPerPage, 50);
int requestedCommits = maxCommits;
if (!StringUtils.isEmpty(length)) {
int l = Integer.parseInt(length);
if (l > 0) {
requestedCommits = l;
}
}
// fetch the requested commits plus some extra so that the last
// commit displayed *likely* has correct lane assignments
CommitList commitList = new CommitList();
commitList.source(rw);
commitList.fillTo(2 * Math.max(requestedCommits, maxCommits));
// determine the appropriate width for the image
int numLanes = 1;
int numCommits = Math.min(requestedCommits, commitList.size());
if (numCommits > 1) {
// determine graph width
Set<String> parents = new TreeSet<String>();
for (int i = 0; i < commitList.size(); i++) {
PlotCommit<Lane> commit = commitList.get(i);
boolean checkLane = false;
if (i < numCommits) {
// commit in visible list
checkLane = true;
// remember parents
for (RevCommit p : commit.getParents()) {
parents.add(p.getName());
}
} else if (parents.contains(commit.getName())) {
// commit outside visible list, but it is a parent of a
// commit in the visible list so we need to know it's lane
// assignment
checkLane = true;
}
if (checkLane) {
int pos = commit.getLane().getPosition();
numLanes = Math.max(numLanes, pos + 1);
}
}
}
int graphWidth = numLanes * LANE_WIDTH + RIGHT_PAD;
int rowHeight = ROW_HEIGHT;
// create an image buffer and render the lanes
BufferedImage image = new BufferedImage(graphWidth, rowHeight * numCommits, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = null;
try {
g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
LanesRenderer renderer = new LanesRenderer();
for (int i = 0; i < commitList.size(); i++) {
PlotCommit<Lane> commit = commitList.get(i);
Graphics row = g.create(0, i * rowHeight, graphWidth, rowHeight);
try {
renderer.paint(row, commit, rowHeight, graphWidth);
} finally {
row.dispose();
row = null;
}
}
} finally {
if (g != null) {
g.dispose();
g = null;
}
}
// write the image buffer to the client
response.setContentType("image/png");
if (numCommits > 1) {
response.setHeader("Cache-Control", "public, max-age=60, must-revalidate");
response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commitList.get(0)).getTime());
}
OutputStream os = response.getOutputStream();
ImageIO.write(image, "png", os);
os.flush();
image.flush();
image = null;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (is != null) {
is.close();
is = null;
}
if (rw != null) {
rw.dispose();
rw = null;
}
if (r != null) {
r.close();
r = null;
}
}
}
use of java.awt.image.BufferedImage in project gephi-plugins-bootcamp by gephi.
the class JPGExporter method execute.
@Override
public boolean execute() {
PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
controller.refreshPreview(workspace);
PreviewProperties props = controller.getModel(workspace).getProperties();
props.putValue("width", width);
props.putValue("height", height);
target = (G2DTarget) controller.getRenderTarget(RenderTarget.G2D_TARGET, workspace);
try {
target.refresh();
Graphics2D pg2 = (Graphics2D) target.getGraphics();
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
pg2.drawImage(img, null, 0, 0);
ImageIO.write(img, "jpg", stream);
stream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
return true;
}
Aggregations