문제

I am writing an image library for fun and i came across a problem that i can't seem to solve. The class is pretty simple: take a picture, process it, display it through JFrame, and finally save it as a BufferedImage (javax.imageio.ImageIO). Here is what my picture looks like through the JFrame (this is my ColorEnhance class... on the Drustan nebula):

The image as seen from the JFrame

Here is what the saved version (a png, but all types ImageIO.write() supports look the same):

The image as seen after it has been saved

I'm not sure where the change occurs, but when I run this through my blur method entire lines appear from nothing in the png... Anyways, here is some code:

public void writeToFile(BufferedImage finalPic, String nameToAppend)
{
    String temp=fileName.replace(".", nameToAppend+".");
    String ext=fileName.substring(fileName.indexOf(".")+1);
    File file=new File(temp);
    try
    {
        ImageIO.write(finalPic, ext.toUpperCase(), file);
        System.out.println("Successfully saved to: "+temp);
    } catch (Exception e) { e.getMessage(); }
}

public void displayImage(String titleName)
{
    ImageIcon icon = new ImageIcon(newPic);
    JFrame frame = new JFrame(titleName);
    JLabel label = new JLabel(icon);
    label.setIcon(icon);
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.setSize(WIDTH, HEIGHT+22);
    frame.setVisible(true);
}

One last thing is that the save works for some processing classes better than others, if you need to see any more code just ask, thanks

올바른 솔루션이 없습니다

다른 팁

Try using PNGImageEncoder from Apache XML Graphics Commons:

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 
PNGImageEncoder encoder = new PNGImageEncoder(new FileOutputStream("file.png"), null);
encoder.encode((RenderedImage) image);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top