Java JPEG png2jpeg(File pngImage, File jpegFile)

Here you can find the source of png2jpeg(File pngImage, File jpegFile)

Description

pngjpeg

License

Open Source License

Declaration

public static boolean png2jpeg(File pngImage, File jpegFile) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;

public class Main {

    public static boolean png2jpeg(File pngImage, File jpegFile) {
        BufferedImage bufferedImage;

        try {/* w w w .  j  av  a 2  s .c  o m*/
            bufferedImage = ImageIO.read(pngImage);

            BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
                    BufferedImage.TYPE_INT_RGB);

            newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);

            ImageIO.write(bufferedImage, "jpg", jpegFile);

            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}

Related

  1. fixImageIOJpegBug(BufferedImage image)
  2. jpeg2BufferedImage(final byte[] jpegImage, final boolean bw)
  3. jpegFromImage(BufferedImage image)