Estou com a seguinte dúvida…
peguei uma imagem e alterei o brilho da msm… depois mandei gerar um JPEG da imagem… ela sai toda preta…
mas qnd ela aparece no Applet o brilho aparece tudo ok…
segue o coidgo
package oggy.components;
import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.ImageIcon;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class FilterTest extends Applet {
private static String imagemOriginal = "D:\\image-1.jpg";
private static String imagemFInal = "D:\\image-1_nova.jpg";
Image src, dst;
boolean red, green, blue;
final int alphaMax = 9;
int alphaLevel = alphaMax;
int brightness = 40;
public void init() {
src = new ImageIcon(imagemOriginal).getImage();//getImage(getDocumentBase(), imagemOriginal);
dst = src;
}
/*************************************************
* @param p_image
* @param width
* @param height
* @param quality
************************************************/
private void salvar(Image p_image, int width, int height, int quality) {
// Fim do cálculo
BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
//graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(p_image, 0, 0, width, height, null);
BufferedOutputStream out;
try {
out = new BufferedOutputStream(new FileOutputStream(imagemFInal));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
} catch (FileNotFoundException e) {
System.out.println("FileNotFoundException " + e.getMessage());
} catch (ImageFormatException e) {
System.out.println("ImageFormatException " + e.getMessage());
} catch (IOException e) {
System.out.println("IOException " + e.getMessage());
}
}
public void paint(Graphics g) {
g.drawImage(dst, 0, 0, this);
}
public boolean keyDown(Event evt, int key) {
switch (key) {
case Event.HOME:
red = false;
green = false;
blue = false;
alphaLevel = alphaMax;
brightness = 0;
break;
case Event.LEFT:
if (--alphaLevel < 0)
alphaLevel = 0;
break;
case Event.RIGHT:
if (++alphaLevel > alphaMax)
alphaLevel = alphaMax;
break;
case Event.UP:
brightness = Math.min(brightness + 10, 100);
break;
case Event.DOWN:
brightness = Math.max(-100, brightness - 10);
break;
case (int)'r':
case (int)'R':
red = !red;
break;
case (int)'g':
case (int)'G':
green = !green;
break;
case (int)'b':
case (int)'B':
blue = !blue;
break;
default:
return false;
}
filterImage();
return true;
}
void filterImage() {
dst = src;
// Apply the brightness filter
dst = createImage(new FilteredImageSource(dst.getSource(),
new BrightnessFilter(brightness)));
// Redraw the image
salvar(dst,200,200,100);
repaint();
}
}
[]´s!
