这是哪个对象的,能不能具体举例!

解决方案 »

  1.   

    // PixelColor.java
    // Get the color of a specific pixel
    import java.awt.image.PixelGrabber;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import java.awt.image.PixelGrabber;
    import java.lang.InterruptedException;public class PixelColor
    {
    public static void main(String[] args)
    {
    ImageIcon imageIcon = new ImageIcon("sample.jpg");
    Image picture = imageIcon.getImage();
    int height = imageIcon.getIconHeight();
    int width = imageIcon.getIconWidth(); int[] pixels = new int[width * height];
    PixelGrabber pg = new PixelGrabber(picture, 0, 0, width, height, pixels, 0, width);
    try
    {
    pg.grabPixels();
    }
    catch (InterruptedException e)
    {
    e.printStackTrace();
    }
    // point(x,y)
    int x = 3;
    int y = 3;
    int pixel = pixels[x + y * width];
    int alpha = (pixel >> 24) & 0xff;
    int red   = (pixel >> 16) & 0xff;
    int green = (pixel >>  8) & 0xff;
    int blue  = (pixel      ) & 0xff;
    System.out.println("height: " + height);
    System.out.println("width: " + width); System.out.println("alpha: " + alpha);
    System.out.println("red: " + red);
    System.out.println("green: " + green);
    System.out.println("blue: " + blue);
    }
    }