I seem to run into a dead end.
I have been able to perform an image transformation into a smaller
image, however I always seem to lose a color channel.
Can anyone help me?
Here is the code below which does the transformation:
//Load Image into a buffer
bufimage = ImageIO.read(file);
//Caculate sizes
int newWidth, newHeight, width,height;
width = bufimage.getWidth();
height = bufimage.getHeight();
newWidth = (int)(width * newSize);
newHeight = (int)(height * newSize);
BufferedImage newbufimage = new BufferedImage(newWidth, newHeight,
BufferedImage.TYPE_INT_ARGB); //Loss of color
BufferedImageOp op = null;
op = new
AffineTransformOp(AffineTransform.getScaleInstance(newSize,newSize),null);
op.filter(bufimage, newbufimage);
//Now write the image to file - 1. opening a new file
String outfile = file.getPath().substring(0,
file.getPath().lastIndexOf('\\') +
1).concat(file.getName().substring(0,
file.getName().indexOf('.')).concat("NEW.jpg"));
File newFile = new File(outfile);
//Write to file
ImageIO.write(newbufimage, "jpg", newFile);
System.out.println("Wrote " + outfile + " to file");
//Clean up
bufimage.flush();
bufimage = null;
Ross Marchant - 09 Aug 2005 23:21 GMT
> I seem to run into a dead end.
>
> I have been able to perform an image transformation into a smaller
> image, however I always seem to lose a color channel.
<snip>
> BufferedImage newbufimage = new BufferedImage(newWidth, newHeight,
> BufferedImage.TYPE_INT_ARGB); //Loss of color
> BufferedImageOp op = null;
Maybe you want TYPE_INT_RGB, because jpg's do not have an alpha channel.
Ross
Ishmael Rufus - 11 Aug 2005 04:07 GMT
When i try using TYPE_INT_RGB I get an ImageOpException thrown: Unable
to transform src image where i call the filter method of "op"
op.filter(bufimage, newbufimage)
Boudewijn Dijkstra - 12 Aug 2005 17:40 GMT
>I seem to run into a dead end.
>
[quoted text clipped - 15 lines]
> BufferedImage newbufimage = new BufferedImage(newWidth, newHeight,
> BufferedImage.TYPE_INT_ARGB); //Loss of color
Graphics2D g = (Graphics2D) newbufimage.createGraphics();
#if defined STATIC_CONTEXT
g.drawImage(bufimage, 0, 0, null);
#elif BOOLEAN_EXPRESSION(this instanceof java.awt.Component)
g.drawImage(bufimage, 0, 0, this);
#endif
/*
> BufferedImageOp op = null;
> op = new
> AffineTransformOp(AffineTransform.getScaleInstance(newSize,newSize),null);
> op.filter(bufimage, newbufimage);
*/
> //Now write the image to file - 1. opening a new file
> String outfile = file.getPath().substring(0,
[quoted text clipped - 9 lines]
> bufimage.flush();
> bufimage = null;