use of org.activiti.image.exception.ActivitiImageException in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method generateBufferedImage.
/**
* Generates an image of what currently is drawn on the canvas.
*
* Throws an {@link ActivitiException} when {@link #close()} is already
* called.
*/
public BufferedImage generateBufferedImage(String imageType) {
if (closed) {
throw new ActivitiImageException("ProcessDiagramGenerator already closed");
}
// Try to remove white space
minX = (minX <= 5) ? 5 : minX;
minY = (minY <= 5) ? 5 : minY;
BufferedImage imageToSerialize = processDiagram;
if (minX >= 0 && minY >= 0) {
imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
}
return imageToSerialize;
}
use of org.activiti.image.exception.ActivitiImageException in project Activiti by Activiti.
the class DefaultProcessDiagramGenerator method getDefaultDiagram.
/**
* Get default diagram image as bytes array
* @return the default diagram image
*/
protected InputStream getDefaultDiagram(String diagramImageFileName) {
String imageFileName = diagramImageFileName != null ? diagramImageFileName : getDefaultDiagramImageFileName();
InputStream imageStream = getClass().getResourceAsStream(imageFileName);
if (imageStream == null) {
throw new ActivitiImageException("Error occurred while getting default diagram image from file: " + imageFileName);
}
return imageStream;
}
use of org.activiti.image.exception.ActivitiImageException in project my_curd by qinyou.
the class CustomProcessDiagramCanvas method generateImage.
/**
* Generates an image of what currently is drawn on the canvas. Throws an {@link ActivitiException} when {@link #close()} is already called.
*/
public InputStream generateImage(String imageType) {
if (closed) {
throw new ActivitiImageException("ProcessDiagramGenerator already closed");
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// Try to remove white space
minX = (minX <= 5) ? 5 : minX;
minY = (minY <= 5) ? 5 : minY;
BufferedImage imageToSerialize = processDiagram;
if (minX >= 0 && minY >= 0) {
imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
}
ImageIO.write(imageToSerialize, imageType, out);
} catch (IOException e) {
throw new ActivitiImageException("Error while generating process image", e);
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ignore) {
// Exception is silently ignored
}
}
return new ByteArrayInputStream(out.toByteArray());
}
use of org.activiti.image.exception.ActivitiImageException in project Activiti by Activiti.
the class DefaultProcessDiagramCanvas method generateImage.
/**
* Generates an image of what currently is drawn on the canvas.
* <p>
* Throws an {@link ActivitiImageException} when {@link #close()} is already
* called.
*/
public InputStream generateImage() {
if (closed) {
throw new ActivitiImageException("ProcessDiagramGenerator already closed");
}
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Writer out;
out = new OutputStreamWriter(stream, "UTF-8");
g.stream(out, true);
return new ByteArrayInputStream(stream.toByteArray());
} catch (UnsupportedEncodingException | SVGGraphics2DIOException e) {
throw new ActivitiImageException("Error while generating process image", e);
}
}
use of org.activiti.image.exception.ActivitiImageException in project my_curd by qinyou.
the class CustomProcessDiagramCanvas method generateBufferedImage.
/**
* Generates an image of what currently is drawn on the canvas. Throws an {@link ActivitiException} when {@link #close()} is already called.
*/
public BufferedImage generateBufferedImage(String imageType) {
if (closed) {
throw new ActivitiImageException("ProcessDiagramGenerator already closed");
}
// Try to remove white space
minX = (minX <= 5) ? 5 : minX;
minY = (minY <= 5) ? 5 : minY;
BufferedImage imageToSerialize = processDiagram;
if (minX >= 0 && minY >= 0) {
imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
}
return imageToSerialize;
}
Aggregations