i want to resize an image (available as a BufferedImage) to a given size.
i tried the following code, which worked fine on my windows system, but is
not workin on linux cause of the "known"
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as
the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:126)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
ERROR.
so my question:
is there another way to resize a BufferedImage and get a byteArray of the
resized image (to upload it to a webserver via ftp) than using a Graphics2D
(see following code i tried)?
Graphics2D g2d = outImage.createGraphics();
g2d.drawImage(inImage, tx, null);
g2d.dispose();
i tried to use
Image test =
inImage.getScaledInstance(scaledW,scaledH,Image.SCALE_DEFAULT);
but the problem is that as result i get a java.awt.Image and i don't know
how to get a BuferedImage from the Image to use the following code
byteOS = new ByteArrayOutputStream();
encoder = JPEGCodec.createJPEGEncoder(byteOS);
encoder.encode(largeImg);
b = byteOS.toByteArray();
server.upload(img_path, (i+1)+".jpg", b);
to code the image as a jpg and get a byteArray to upload it to the server
thanks for help!
Thomas P.
Perhaps you will find this code useful:
public static void scaleStream(File in, File out, double scale)
throws IOException
{
// can't use standard cache dir in servlet context.
ImageIO.setUseCache(false);
BufferedImage image = ImageIO.read(in);
AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
BufferedImage scaledImage = op.filter(image, null);
ImageIO.write(scaledImage, "jpg", out);
}
Marshall
AffineTransformOp op = new
AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), null);
outImage = op.filter(inImage, null);
where outImage and inImage are BufferImage.
"Pfanzelter Thomas" <i...@efftrade.at> schrieb im Newsbeitrag
news:3c99...@news.uni-linz.ac.at...