Java BufferedImage Pixel getRandomPixel(final String fileName)

Here you can find the source of getRandomPixel(final String fileName)

Description

get Random Pixel

License

Apache License

Declaration

public static String getRandomPixel(final String fileName) throws IOException 

Method Source Code


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

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Main {
    private static BufferedImage img;
    private static String file;

    public static String getRandomPixel(final String fileName) throws IOException {
        if (!fileName.equals(file)) {
            img = ImageIO.read(new File(fileName));
            file = fileName;/* w w w.j  a va2  s . c om*/
        }
        return String.format("#%06X", (0xFFFFFF
                & img.getRGB((int) (Math.random() * img.getWidth()), (int) (Math.random() * img.getHeight()))));
    }
}

Related

  1. extractFromPixeldata(short[] pixeldata, int columns, int stride, int mask, byte[] ovlyData, int off, int length)
  2. imageFromIntArray(int[] pixels, int w, int h)
  3. pixels(BufferedImage image)
  4. pixelsb(BufferedImage image)
  5. pixelsFromBufferedImage(final BufferedImage image)