Java Utililty Methods JPEG

List of utility methods to do JPEG

Description

The list of methods to do JPEG are organized into topic(s).

Method

BufferedImagefixImageIOJpegBug(BufferedImage image)
fix Image IO Jpeg Bug
int type = image.getType();
if (type != BufferedImage.TYPE_INT_RGB) {
    int width = image.getWidth();
    int height = image.getHeight();
    BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    int[] pixels2 = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
    int[] pixels = image.getRGB(0, 0, width, height, null, 0, width);
    for (int i = 0; i < pixels.length; i++) {
...
BufferedImagejpeg2BufferedImage(final byte[] jpegImage, final boolean bw)
Convierte una imagen JPEG en una BufferedImage de AWT.
final BufferedImage original = ImageIO.read(new ByteArrayInputStream(jpegImage));
if (!bw) {
    return original;
final BufferedImage binarized = new BufferedImage(original.getWidth(), original.getHeight(),
        BufferedImage.TYPE_BYTE_BINARY);
int newPixel;
final int threshold = 230;
...
byte[]jpegFromImage(BufferedImage image)
jpeg From Image
ByteArrayOutputStream bos = new ByteArrayOutputStream(128000);
javax.imageio.ImageIO.write(image, "jpg", bos);
byte[] jpegBits = bos.toByteArray();
bos.close();
return jpegBits;
booleanpng2jpeg(File pngImage, File jpegFile)
pngjpeg
BufferedImage bufferedImage;
try {
    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;
...