Java Utililty Methods BufferedImage Size Get

List of utility methods to do BufferedImage Size Get

Description

The list of methods to do BufferedImage Size Get are organized into topic(s).

Method

DimensiongetDimension(BufferedImage img)
get Dimension
int h = img.getHeight();
int w = img.getWidth();
Dimension dim = new Dimension(w, h);
return dim;
DimensiongetDimension(File f)
get Dimension
if (f == null || !f.exists() || !f.canRead()) {
    return null;
BufferedImage bi;
try {
    bi = ImageIO.read(f);
    return new Dimension(bi.getWidth(), bi.getHeight());
} catch (IOException ex) {
...
DimensiongetDimension(final Image anImage, final ImageObserver obs)
get Dimension
return new Dimension(anImage.getWidth(obs), anImage.getHeight(obs));
int[]getDimensions(byte[] image)
get Dimensions
try {
    BufferedImage source = ImageIO.read(new ByteArrayInputStream(image));
    if (source == null) {
        return null;
    int[] dimensions = new int[2];
    dimensions[1] = source.getHeight();
    dimensions[0] = source.getWidth();
...
DimensiongetSize(BufferedImage image)
get Size
return new Dimension(image.getWidth(), image.getHeight());
int[]getSize(int width, int height, Image image)
get Size
int targetWidth = image.getWidth(null);
int targetHeight = image.getHeight(null);
double scaling = getScaling(targetWidth, targetHeight, width, height);
long standardWidth = Math.round(targetWidth * scaling);
long standardHeight = Math.round(targetHeight * scaling);
return new int[] { Integer.parseInt(Long.toString(standardWidth)),
        Integer.parseInt(String.valueOf(standardHeight)) };
int[]getSizeByHeight(int height, Image image)
get Size By Height
int targetWidth = image.getWidth(null);
int targetHeight = image.getHeight(null);
long width = Math.round((targetWidth * height) / (targetHeight * 1.00f));
return new int[] { Integer.parseInt(String.valueOf(width)), height };
BufferedImagegetSizedImage(final URL url, final Dimension size)
get Sized Image
final BufferedImage image = ImageIO.read(url);
final BufferedImage bufferedImage = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, size.width, size.height, null);
g.dispose();
return bufferedImage;