Java BufferedImage Operation fixImage(BufferedImage img, String ext)

Here you can find the source of fixImage(BufferedImage img, String ext)

Description

Fixes image type based on the file extension.

License

Apache License

Parameter

Parameter Description
img a parameter
ext a parameter

Declaration

static BufferedImage fixImage(BufferedImage img, String ext) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.image.BufferedImage;

public class Main {
    /**/*  w  w w . j a  v  a2  s.  c  om*/
     * Fixes image type based on the file extension.  If you write argb images as jpg, things
     * get messed up.
     * @param img
     * @param ext
     * @return
     */
    static BufferedImage fixImage(BufferedImage img, String ext) {
        if ("jpg".equalsIgnoreCase(ext)) {
            // log.info("Adjusting JPG image during Java Colorspace Issue for file " + file);
            // set rgb color for image, because of issues in java jpeg colorspaces
            int w = img.getWidth();
            int h = img.getHeight();
            BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            int[] rgb = img.getRGB(0, 0, w, h, null, 0, w);
            newImage.setRGB(0, 0, w, h, rgb, 0, w);
            img = newImage;
        }
        return img;
    }
}

Related

  1. findDifference(BufferedImage img2, BufferedImage img1)
  2. findDominantColor(BufferedImage paramBufferedImage)
  3. findLegacyColorModel(BufferedImage image)
  4. findLegendLH(BufferedImage bufferedImage)
  5. findTranslation(AffineTransform at, BufferedImage bi)
  6. floatBufferToGrayBufferedImage(FloatBuffer floatBuffer, BufferedImage bi)
  7. floodFill(BufferedImage img, int startX, int startY, Color targetColor, Color replacementColor)
  8. fuzzyCompare(final BufferedImage img1, final BufferedImage img2, final double colorTolerance, final double pixelTolerance, final int fuzzyBlockDimension)
  9. fuzzyEquals(BufferedImage a, BufferedImage b, int threshold)