use of java.awt.image.RenderedImage in project jersey by jersey.
the class RenderedImageTypeTest method testPostUndefined.
@Test
public void testPostUndefined() throws Exception {
final InputStream stream = getClass().getResourceAsStream("duke_rocket.gif");
Response response = target("sub").request().post(Entity.entity(stream, "application/octet-stream"));
assertThat(Long.valueOf(response.getHeaderString("Content-Length")), greaterThan(0L));
final RenderedImage image = response.readEntity(RenderedImage.class);
assertThat(image, notNullValue());
response = target().request().post(Entity.entity(image, "image/png"));
assertThat(response.readEntity(RenderedImage.class), notNullValue());
assertThat(Long.valueOf(response.getHeaderString("Content-Length")), greaterThan(0L));
}
use of java.awt.image.RenderedImage in project jdk8u_jdk by JetBrains.
the class TestLayoutVsICU method show.
private void show(String arg) throws ParserConfigurationException, SAXException, IOException {
id = "<none>";
File xmlFile = new File(arg);
if (!xmlFile.exists()) {
throw new FileNotFoundException("Can't open input XML file " + arg);
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
if (OPT_VERBOSE) {
System.out.println("# Parsing " + xmlFile.getAbsolutePath());
}
Document doc = db.parse(xmlFile);
Element e = doc.getDocumentElement();
if (!XML_LAYOUT_TESTS.equals(e.getNodeName())) {
throw new IllegalArgumentException("Document " + xmlFile.getAbsolutePath() + " does not have <layout-tests> as its base");
}
NodeList testCases = e.getElementsByTagName(XML_TEST_CASE);
for (int caseNo = 0; caseNo < testCases.getLength(); caseNo++) {
final Node testCase = testCases.item(caseNo);
final Map<String, String> testCaseAttrs = attrs(testCase);
id = testCaseAttrs.get(XML_ID);
final String script = testCaseAttrs.get(XML_SCRIPT);
String testText = null;
Integer[] expectGlyphs = null;
Integer[] expectIndices = null;
Map<String, String> fontAttrs = null;
if (OPT_VERBOSE) {
System.out.println("#" + caseNo + " id=" + id + ", script=" + script);
}
NodeList children = testCase.getChildNodes();
for (int sub = 0; sub < children.getLength(); sub++) {
Node n = children.item(sub);
if (n.getNodeType() != Node.ELEMENT_NODE)
continue;
String nn = n.getNodeName();
if (nn.equals(XML_TEST_FONT)) {
fontAttrs = attrs(n);
} else if (nn.equals(XML_TEST_TEXT)) {
testText = n.getTextContent();
} else if (nn.equals(XML_RESULT_GLYPHS)) {
String hex = n.getTextContent();
expectGlyphs = parseHexArray(hex);
} else if (nn.equals(XML_RESULT_INDICES)) {
String hex = n.getTextContent();
expectIndices = parseHexArray(hex);
} else if (OPT_VERBOSE) {
System.out.println("Ignoring node " + nn);
}
}
if (fontAttrs == null) {
throw new IllegalArgumentException(id + " Missing node " + XML_TEST_FONT);
}
if (testText == null) {
throw new IllegalArgumentException(id + " Missing node " + XML_TEST_TEXT);
}
String fontName = fontAttrs.get(XML_NAME);
Font f = getFont(fontName, fontAttrs);
if (f == null) {
if (OPT_FAILMISSING) {
throw new MissingResourceException("Missing font, abort test", Font.class.getName(), fontName);
}
System.out.println("Skipping " + id + " because font is missing: " + fontName);
skipped++;
continue;
}
FontRenderContext frc = new FontRenderContext(null, true, true);
TextLayout tl = new TextLayout(testText, f, frc);
final List<GlyphVector> glyphs = new ArrayList<GlyphVector>();
Graphics2D myg2 = new Graphics2D() {
@Override
public void draw(Shape s) {
// TODO Auto-generated method stub
}
@Override
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
// TODO Auto-generated method stub
return false;
}
@Override
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
// TODO Auto-generated method stub
}
@Override
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
// TODO Auto-generated method stub
}
@Override
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
// TODO Auto-generated method stub
}
@Override
public void drawString(String str, int x, int y) {
// TODO Auto-generated method stub
}
@Override
public void drawString(String str, float x, float y) {
// TODO Auto-generated method stub
}
@Override
public void drawString(AttributedCharacterIterator iterator, int x, int y) {
// TODO Auto-generated method stub
}
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
// TODO Auto-generated method stub
}
@Override
public void drawGlyphVector(GlyphVector g, float x, float y) {
if (x != 0.0 || y != 0.0) {
throw new InternalError("x,y should be 0 but got " + x + "," + y);
}
//System.err.println("dGV : " + g.toString() + " @ "+x+","+y);
glyphs.add(g);
}
@Override
public void fill(Shape s) {
// TODO Auto-generated method stub
}
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
// TODO Auto-generated method stub
return false;
}
@Override
public GraphicsConfiguration getDeviceConfiguration() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setComposite(Composite comp) {
// TODO Auto-generated method stub
}
@Override
public void setPaint(Paint paint) {
// TODO Auto-generated method stub
}
@Override
public void setStroke(Stroke s) {
// TODO Auto-generated method stub
}
@Override
public void setRenderingHint(Key hintKey, Object hintValue) {
// TODO Auto-generated method stub
}
@Override
public Object getRenderingHint(Key hintKey) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setRenderingHints(Map<?, ?> hints) {
// TODO Auto-generated method stub
}
@Override
public void addRenderingHints(Map<?, ?> hints) {
// TODO Auto-generated method stub
}
@Override
public RenderingHints getRenderingHints() {
// TODO Auto-generated method stub
return null;
}
@Override
public void translate(int x, int y) {
// TODO Auto-generated method stub
}
@Override
public void translate(double tx, double ty) {
// TODO Auto-generated method stub
}
@Override
public void rotate(double theta) {
// TODO Auto-generated method stub
}
@Override
public void rotate(double theta, double x, double y) {
// TODO Auto-generated method stub
}
@Override
public void scale(double sx, double sy) {
// TODO Auto-generated method stub
}
@Override
public void shear(double shx, double shy) {
// TODO Auto-generated method stub
}
@Override
public void transform(AffineTransform Tx) {
// TODO Auto-generated method stub
}
@Override
public void setTransform(AffineTransform Tx) {
// TODO Auto-generated method stub
}
@Override
public AffineTransform getTransform() {
// TODO Auto-generated method stub
return null;
}
@Override
public Paint getPaint() {
// TODO Auto-generated method stub
return null;
}
@Override
public Composite getComposite() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setBackground(Color color) {
// TODO Auto-generated method stub
}
@Override
public Color getBackground() {
// TODO Auto-generated method stub
return null;
}
@Override
public Stroke getStroke() {
// TODO Auto-generated method stub
return null;
}
@Override
public void clip(Shape s) {
// TODO Auto-generated method stub
}
@Override
public FontRenderContext getFontRenderContext() {
// TODO Auto-generated method stub
return null;
}
@Override
public Graphics create() {
// TODO Auto-generated method stub
return null;
}
@Override
public Color getColor() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setColor(Color c) {
// TODO Auto-generated method stub
}
@Override
public void setPaintMode() {
// TODO Auto-generated method stub
}
@Override
public void setXORMode(Color c1) {
// TODO Auto-generated method stub
}
@Override
public Font getFont() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setFont(Font font) {
// TODO Auto-generated method stub
}
@Override
public FontMetrics getFontMetrics(Font f) {
// TODO Auto-generated method stub
return null;
}
@Override
public Rectangle getClipBounds() {
// TODO Auto-generated method stub
return null;
}
@Override
public void clipRect(int x, int y, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void setClip(int x, int y, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public Shape getClip() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setClip(Shape clip) {
// TODO Auto-generated method stub
}
@Override
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
// TODO Auto-generated method stub
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
// TODO Auto-generated method stub
}
@Override
public void fillRect(int x, int y, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void clearRect(int x, int y, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
// TODO Auto-generated method stub
}
@Override
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
// TODO Auto-generated method stub
}
@Override
public void drawOval(int x, int y, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void fillOval(int x, int y, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
// TODO Auto-generated method stub
}
@Override
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
// TODO Auto-generated method stub
}
@Override
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
// TODO Auto-generated method stub
}
@Override
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
// TODO Auto-generated method stub
}
@Override
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
// TODO Auto-generated method stub
}
@Override
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) {
// TODO Auto-generated method stub
return false;
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
};
tl.draw(myg2, 0, 0);
if (glyphs.size() != 1) {
err("drew " + glyphs.size() + " times - expected 1");
total++;
bad++;
continue;
}
boolean isBad = false;
GlyphVector gv = glyphs.get(0);
// GLYPHS
int[] gotGlyphs = gv.getGlyphCodes(0, gv.getNumGlyphs(), new int[gv.getNumGlyphs()]);
// go up to this count
int count = Math.min(gotGlyphs.length, expectGlyphs.length);
for (int i = 0; i < count; i++) {
if (gotGlyphs[i] != expectGlyphs[i]) {
err("@" + i + " - got \tglyph 0x" + Integer.toHexString(gotGlyphs[i]) + " wanted 0x" + Integer.toHexString(expectGlyphs[i]));
isBad = true;
break;
}
}
// INDICES
int[] gotIndices = gv.getGlyphCharIndices(0, gv.getNumGlyphs(), new int[gv.getNumGlyphs()]);
for (int i = 0; i < count; i++) {
if (gotIndices[i] != expectIndices[i]) {
err("@" + i + " - got \tindex 0x" + Integer.toHexString(gotGlyphs[i]) + " wanted 0x" + Integer.toHexString(expectGlyphs[i]));
isBad = true;
break;
}
}
// COUNT
if (gotGlyphs.length != expectGlyphs.length) {
System.out.println("Got " + gotGlyphs.length + " wanted " + expectGlyphs.length + " glyphs");
isBad = true;
} else {
if (OPT_VERBOSE) {
System.out.println(">> OK: " + gotGlyphs.length + " glyphs");
}
}
if (isBad) {
bad++;
System.out.println("* FAIL: " + id + " /\t" + fontName);
} else {
System.out.println("* OK : " + id + " /\t" + fontName);
}
total++;
}
}
use of java.awt.image.RenderedImage in project ats-framework by Axway.
the class LocalSystemOperations method createScreenshot.
/**
* Creates display screenshot and save it in an image file.<br/>
* The currently supported image formats/types are PNG, JPG, JPEG, GIF and BMP<br/>
* <br/>
* <b>NOTE:</b> For remote usage, the filePath value must be only the image file extension eg. ".PNG"
*
* @param filePath the screenshot image file path. If the file extension is not specified, the default format PNG will be used
* @return the full path to the locally saved screenshot image file
*/
public String createScreenshot(String filePath) {
try {
if (filePath == null) {
filePath = "." + DEFAULT_SCREENSHOT_FILE_EXT;
}
// extract and validate the image file type
String fileType = null;
int extensionIndex = filePath.lastIndexOf('.');
if (extensionIndex >= 0 && filePath.length() > (extensionIndex + 1)) {
fileType = filePath.substring(extensionIndex + 1);
try {
ImageType.valueOf(fileType.toUpperCase());
} catch (IllegalArgumentException iae) {
throw new SystemOperationException("Unsupported image file type \"" + fileType + "\". Use one of these: " + Arrays.toString(ImageType.values()));
}
} else {
log.info("The screenshot file extension was not specified, the default one '.png' will be used instead");
fileType = DEFAULT_SCREENSHOT_FILE_EXT;
filePath = filePath + "." + fileType;
}
File imageFile = null;
if (filePath.indexOf('.') == 0) {
imageFile = File.createTempFile("ats_", "." + fileType);
imageFile.deleteOnExit();
filePath = imageFile.getCanonicalPath();
} else {
imageFile = new File(filePath);
}
Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
RenderedImage renderedImage = new Robot().createScreenCapture(area);
ImageIO.write(renderedImage, fileType, imageFile);
} catch (Exception e) {
throw new SystemOperationException("Could not write Screenshot image to file '" + filePath + "'", e);
}
return filePath;
}
use of java.awt.image.RenderedImage in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method drawRenderableImage.
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
if (img == null) {
return;
}
AffineTransform pipeTransform = transform;
AffineTransform concatTransform = new AffineTransform(xform);
concatTransform.concatenate(pipeTransform);
AffineTransform reverseTransform;
RenderContext rc = new RenderContext(concatTransform);
try {
reverseTransform = pipeTransform.createInverse();
} catch (NoninvertibleTransformException nte) {
rc = new RenderContext(pipeTransform);
reverseTransform = new AffineTransform();
}
RenderedImage rendering = img.createRendering(rc);
drawRenderedImage(rendering, reverseTransform);
}
use of java.awt.image.RenderedImage in project jdk8u_jdk by JetBrains.
the class PNGImageWriter method write.
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IIOException {
if (stream == null) {
throw new IllegalStateException("output == null!");
}
if (image == null) {
throw new IllegalArgumentException("image == null!");
}
if (image.hasRaster()) {
throw new UnsupportedOperationException("image has a Raster!");
}
RenderedImage im = image.getRenderedImage();
SampleModel sampleModel = im.getSampleModel();
this.numBands = sampleModel.getNumBands();
// Set source region and subsampling to default values
this.sourceXOffset = im.getMinX();
this.sourceYOffset = im.getMinY();
this.sourceWidth = im.getWidth();
this.sourceHeight = im.getHeight();
this.sourceBands = null;
this.periodX = 1;
this.periodY = 1;
if (param != null) {
// Get source region and subsampling factors
Rectangle sourceRegion = param.getSourceRegion();
if (sourceRegion != null) {
Rectangle imageBounds = new Rectangle(im.getMinX(), im.getMinY(), im.getWidth(), im.getHeight());
// Clip to actual image bounds
sourceRegion = sourceRegion.intersection(imageBounds);
sourceXOffset = sourceRegion.x;
sourceYOffset = sourceRegion.y;
sourceWidth = sourceRegion.width;
sourceHeight = sourceRegion.height;
}
// Adjust for subsampling offsets
int gridX = param.getSubsamplingXOffset();
int gridY = param.getSubsamplingYOffset();
sourceXOffset += gridX;
sourceYOffset += gridY;
sourceWidth -= gridX;
sourceHeight -= gridY;
// Get subsampling factors
periodX = param.getSourceXSubsampling();
periodY = param.getSourceYSubsampling();
int[] sBands = param.getSourceBands();
if (sBands != null) {
sourceBands = sBands;
numBands = sourceBands.length;
}
}
// Compute output dimensions
int destWidth = (sourceWidth + periodX - 1) / periodX;
int destHeight = (sourceHeight + periodY - 1) / periodY;
if (destWidth <= 0 || destHeight <= 0) {
throw new IllegalArgumentException("Empty source region!");
}
// Compute total number of pixels for progress notification
this.totalPixels = destWidth * destHeight;
this.pixelsDone = 0;
// Create metadata
IIOMetadata imd = image.getMetadata();
if (imd != null) {
metadata = (PNGMetadata) convertImageMetadata(imd, ImageTypeSpecifier.createFromRenderedImage(im), null);
} else {
metadata = new PNGMetadata();
}
if (param != null) {
// Use Adam7 interlacing if set in write param
switch(param.getProgressiveMode()) {
case ImageWriteParam.MODE_DEFAULT:
metadata.IHDR_interlaceMethod = 1;
break;
case ImageWriteParam.MODE_DISABLED:
metadata.IHDR_interlaceMethod = 0;
break;
}
}
// Initialize bitDepth and colorType
metadata.initialize(new ImageTypeSpecifier(im), numBands);
// Overwrite IHDR width and height values with values from image
metadata.IHDR_width = destWidth;
metadata.IHDR_height = destHeight;
this.bpp = numBands * ((metadata.IHDR_bitDepth == 16) ? 2 : 1);
// Initialize scaling tables for this image
initializeScaleTables(sampleModel.getSampleSize());
clearAbortRequest();
processImageStarted(0);
try {
write_magic();
write_IHDR();
write_cHRM();
write_gAMA();
write_iCCP();
write_sBIT();
write_sRGB();
write_PLTE();
write_hIST();
write_tRNS();
write_bKGD();
write_pHYs();
write_sPLT();
write_tIME();
write_tEXt();
write_iTXt();
write_zTXt();
writeUnknownChunks();
write_IDAT(im);
if (abortRequested()) {
processWriteAborted();
} else {
// Finish up and inform the listeners we are done
writeIEND();
processImageComplete();
}
} catch (IOException e) {
throw new IIOException("I/O error writing PNG file!", e);
}
}
Aggregations