use of java.awt.image.BufferedImage in project camel by apache.
the class CxfMtomDisabledProducerPayloadModeTest method testProducer.
@Override
public void testProducer() throws Exception {
if (MtomTestHelper.isAwtHeadless(logger, null)) {
return;
}
Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.MTOM_DISABLED_REQ_MESSAGE)).getDocumentElement()));
CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null);
exchange.getIn().setBody(body);
exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
}
});
// process response - verify response attachments
CxfPayload<?> out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());
DataHandler dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_PHOTO_CID);
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
dr = exchange.getOut().getAttachment(MtomTestHelper.RESP_IMAGE_CID);
Assert.assertEquals("image/jpeg", dr.getContentType());
BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());
}
use of java.awt.image.BufferedImage in project jforum2 by rafaelsteil.
the class AttachmentCommon method createSaveThumb.
private void createSaveThumb(String path) {
try {
BufferedImage image = ImageUtils.resizeImage(path, ImageUtils.IMAGE_JPEG, SystemGlobals.getIntValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_W), SystemGlobals.getIntValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_H));
ImageUtils.saveImage(image, path + "_thumb", ImageUtils.IMAGE_JPEG);
} catch (Exception e) {
logger.error(e.toString(), e);
}
}
use of java.awt.image.BufferedImage in project processing by processing.
the class Mode method makeGradient.
public Image makeGradient(String attribute, int wide, int high) {
int top = getColor(attribute + ".gradient.top").getRGB();
int bot = getColor(attribute + ".gradient.bottom").getRGB();
// float r1 = (top >> 16) & 0xff;
// float g1 = (top >> 8) & 0xff;
// float b1 = top & 0xff;
// float r2 = (bot >> 16) & 0xff;
// float g2 = (bot >> 8) & 0xff;
// float b2 = bot & 0xff;
BufferedImage outgoing = new BufferedImage(wide, high, BufferedImage.TYPE_INT_RGB);
int[] row = new int[wide];
WritableRaster wr = outgoing.getRaster();
for (int i = 0; i < high; i++) {
// Arrays.fill(row, (255 - (i + GRADIENT_TOP)) << 24);
// int r = (int) PApplet.map(i, 0, high-1, r1, r2);
int rgb = PApplet.lerpColor(top, bot, i / (float) (high - 1), PConstants.RGB);
Arrays.fill(row, rgb);
// System.out.println(PApplet.hex(row[0]));
wr.setDataElements(0, i, wide, 1, row);
}
// }
return outgoing;
}
use of java.awt.image.BufferedImage in project processing by processing.
the class PApplet method loadImage.
// /**
// * @param extension the type of image to load, for example "png", "gif", "jpg"
// */
// public PImage loadImage(String filename, String extension) {
// return loadImage(filename, extension, null);
// }
// /**
// * @nowebref
// */
// public PImage loadImage(String filename, Object params) {
// return loadImage(filename, null, params);
// }
/**
* @param extension type of image to load, for example "png", "gif", "jpg"
*/
public PImage loadImage(String filename, String extension) {
// If this runs on background, requestImage() already called await... on the main thread
if (g != null && !Thread.currentThread().getName().startsWith(ASYNC_IMAGE_LOADER_THREAD_PREFIX)) {
g.awaitAsyncSaveCompletion(filename);
}
if (extension == null) {
String lower = filename.toLowerCase();
int dot = filename.lastIndexOf('.');
if (dot == -1) {
// no extension found
extension = "unknown";
}
extension = lower.substring(dot + 1);
// check for, and strip any parameters on the url, i.e.
// filename.jpg?blah=blah&something=that
int question = extension.indexOf('?');
if (question != -1) {
extension = extension.substring(0, question);
}
}
// just in case. them users will try anything!
extension = extension.toLowerCase();
if (extension.equals("tga")) {
try {
PImage image = loadImageTGA(filename);
// }
return image;
} catch (IOException e) {
printStackTrace(e);
return null;
}
}
if (extension.equals("tif") || extension.equals("tiff")) {
byte[] bytes = loadBytes(filename);
PImage image = (bytes == null) ? null : PImage.loadTIFF(bytes);
// }
return image;
}
// http://dev.processing.org/bugs/show_bug.cgi?id=392
try {
if (extension.equals("jpg") || extension.equals("jpeg") || extension.equals("gif") || extension.equals("png") || extension.equals("unknown")) {
byte[] bytes = loadBytes(filename);
if (bytes == null) {
return null;
} else {
//Image awtImage = Toolkit.getDefaultToolkit().createImage(bytes);
Image awtImage = new ImageIcon(bytes).getImage();
if (awtImage instanceof BufferedImage) {
BufferedImage buffImage = (BufferedImage) awtImage;
int space = buffImage.getColorModel().getColorSpace().getType();
if (space == ColorSpace.TYPE_CMYK) {
System.err.println(filename + " is a CMYK image, " + "only RGB images are supported.");
return null;
/*
// wishful thinking, appears to not be supported
// https://community.oracle.com/thread/1272045?start=0&tstart=0
BufferedImage destImage =
new BufferedImage(buffImage.getWidth(),
buffImage.getHeight(),
BufferedImage.TYPE_3BYTE_BGR);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(buffImage, destImage);
image = new PImage(destImage);
*/
}
}
PImage image = new PImage(awtImage);
if (image.width == -1) {
System.err.println("The file " + filename + " contains bad image data, or may not be an image.");
}
// if it's a .gif image, test to see if it has transparency
if (extension.equals("gif") || extension.equals("png") || extension.equals("unknown")) {
image.checkAlpha();
}
// if (params != null) {
// image.setParams(g, params);
// }
image.parent = this;
return image;
}
}
} catch (Exception e) {
// show error, but move on to the stuff below, see if it'll work
printStackTrace(e);
}
if (loadImageFormats == null) {
loadImageFormats = ImageIO.getReaderFormatNames();
}
if (loadImageFormats != null) {
for (int i = 0; i < loadImageFormats.length; i++) {
if (extension.equals(loadImageFormats[i])) {
return loadImageIO(filename);
// PImage image = loadImageIO(filename);
// if (params != null) {
// image.setParams(g, params);
// }
// return image;
}
}
}
// failed, could not load image after all those attempts
System.err.println("Could not find a method to load " + filename);
return null;
}
use of java.awt.image.BufferedImage in project processing by processing.
the class PApplet method loadImageIO.
// done internally by ImageIcon
// /**
// * Load an AWT image synchronously by setting up a MediaTracker for
// * a single image, and blocking until it has loaded.
// */
// protected PImage loadImageMT(Image awtImage) {
// MediaTracker tracker = new MediaTracker(this);
// tracker.addImage(awtImage, 0);
// try {
// tracker.waitForAll();
// } catch (InterruptedException e) {
// //e.printStackTrace(); // non-fatal, right?
// }
//
// PImage image = new PImage(awtImage);
// image.parent = this;
// return image;
// }
/**
* Use Java 1.4 ImageIO methods to load an image.
*/
protected PImage loadImageIO(String filename) {
InputStream stream = createInput(filename);
if (stream == null) {
System.err.println("The image " + filename + " could not be found.");
return null;
}
try {
BufferedImage bi = ImageIO.read(stream);
PImage outgoing = new PImage(bi.getWidth(), bi.getHeight());
outgoing.parent = this;
bi.getRGB(0, 0, outgoing.width, outgoing.height, outgoing.pixels, 0, outgoing.width);
// check the alpha for this image
// was gonna call getType() on the image to see if RGB or ARGB,
// but it's not actually useful, since gif images will come through
// as TYPE_BYTE_INDEXED, which means it'll still have to check for
// the transparency. also, would have to iterate through all the other
// types and guess whether alpha was in there, so.. just gonna stick
// with the old method.
outgoing.checkAlpha();
stream.close();
// return the image
return outgoing;
} catch (Exception e) {
printStackTrace(e);
return null;
}
}
Aggregations