java类java.awt.image.PixelGrabber的实例源码

ImageUtils.java 文件源码 项目:webcamstudio 阅读 25 收藏 0 点赞 0 评论 0
/**
    * Cretae a BufferedImage from an ImageProducer.
    * @param producer the ImageProducer
    * @return a new TYPE_INT_ARGB BufferedImage
    */
   public static BufferedImage createImage(ImageProducer producer) {
    PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new RuntimeException("Image fetch interrupted");
    }
    if ((pg.status() & ImageObserver.ABORT) != 0) {
                   throw new RuntimeException("Image fetch aborted");
               }
    if ((pg.status() & ImageObserver.ERROR) != 0) {
                   throw new RuntimeException("Image fetch error");
               }
    BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
    p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
    return p;
}
ImageLoadingDialog.java 文件源码 项目:WorldOfMoreWires 阅读 22 收藏 0 点赞 0 评论 0
private static int[][] getPixels(Image image) throws IOException {
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    int pix[] = new int[w * h];
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, w, h, pix, 0, w);

    try {
        if (!grabber.grabPixels()) {
            throw new IOException("Grabber returned false: " + grabber.status());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    int pixels[][] = new int[w][h];
    for (int x = w; x-- > 0; ) {
        for (int y = h; y-- > 0; ) {
            pixels[x][y] = pix[y * w + x];
        }
    }

    return pixels;
}
TestQuantize.java 文件源码 项目:WorldOfMoreWires 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Snag the pixels from an image.
 */
public static int[][] getPixels(Image image) throws IOException {
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    int pix[] = new int[w * h];
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, w, h, pix, 0, w);

    try {
        if (!grabber.grabPixels()) {
            throw new IOException("Grabber returned false: " +
                    grabber.status());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    int pixels[][] = new int[w][h];
    for (int x = w; x-- > 0; ) {
        for (int y = h; y-- > 0; ) {
            pixels[x][y] = pix[y * w + x];
        }
    }

    return pixels;
}
GraphicsUtils.java 文件源码 项目:vectorgraphics2d 阅读 25 收藏 0 点赞 0 评论 0
/**
 * This method returns {@code true} if the specified image has the
 * possibility to store transparent pixels.
 * Inspired by http://www.exampledepot.com/egs/java.awt.image/HasAlpha.html
 * @param image Image that should be checked for alpha channel.
 * @return {@code true} if the specified image can have transparent pixels,
 *         {@code false} otherwise
 */
public static boolean hasAlpha(Image image) {
    ColorModel cm;
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage) image;
        cm = bimage.getColorModel();
    } else {
        // Use a pixel grabber to retrieve the image's color model;
        // grabbing a single pixel is usually sufficient
        PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
        try {
            pg.grabPixels();
        } catch (InterruptedException e) {
            return false;
        }
        // Get the image's color model
        cm = pg.getColorModel();
    }
    return cm.hasAlpha();
}
AttachBL.java 文件源码 项目:Genji 阅读 19 收藏 0 点赞 0 评论 0
private static boolean hasAlpha(Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage)image;
        return bimage.getColorModel().hasAlpha();
    }

    // grabbing a single pixel is usually sufficient
    PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}
Image.java 文件源码 项目:Lucee 阅读 24 收藏 0 点赞 0 评论 0
/**
 * This method returns true if the specified image has transparent pixels
 * @param image
 * @return
 */
public static boolean hasAlpha(java.awt.Image image) {
    // If buffered image, the color model is readily available
    if (image instanceof BufferedImage) {
        BufferedImage bimage = (BufferedImage)image;
        return bimage.getColorModel().hasAlpha();
    }

    // Use a pixel grabber to retrieve the image's color model;
    // grabbing a single pixel is usually sufficient
     PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }

    // Get the image's color model
    ColorModel cm = pg.getColorModel();
    return cm.hasAlpha();
}
ImageUtils.java 文件源码 项目:Lucee 阅读 33 收藏 0 点赞 0 评论 0
/**
    * Cretae a BufferedImage from an ImageProducer.
    * @param producer the ImageProducer
    * @return a new TYPE_INT_ARGB BufferedImage
    */
   public static BufferedImage createImage(ImageProducer producer) {
    PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new RuntimeException("Image fetch interrupted");
    }
    if ((pg.status() & ImageObserver.ABORT) != 0)
        throw new RuntimeException("Image fetch aborted");
    if ((pg.status() & ImageObserver.ERROR) != 0)
        throw new RuntimeException("Image fetch error");
    BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
    p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
    return p;
}
ImageUtil.java 文件源码 项目:feathers-sdk 阅读 30 收藏 0 点赞 0 评论 0
public static PixelGrabber getPixelGrabber(Image image, String location)
 {
     PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, true);

     try
     {
         pixelGrabber.grabPixels();
     }
     catch (InterruptedException interruptedException)
     {
      if (Trace.error)
      {
       interruptedException.printStackTrace();
      }
         throw new RuntimeException("Failed to grab pixels for image " + location);
     }

  if (((pixelGrabber.getStatus() & ImageObserver.WIDTH) == 0) ||
((pixelGrabber.getStatus() & ImageObserver.HEIGHT) == 0))
  {
   throw new RuntimeException("Failed to grab pixels for image " + location);
  }

     return pixelGrabber;
 }
LosslessImage.java 文件源码 项目:feathers-sdk 阅读 25 收藏 0 点赞 0 评论 0
private void init(Image image)
{
       PixelGrabber pixelGrabber = ImageUtil.getPixelGrabber(image, location);

    width = pixelGrabber.getWidth();
    height = pixelGrabber.getHeight();
    Object p = pixelGrabber.getPixels();

    if (p != null)
    {
        Class ct = p.getClass().getComponentType();
        if (ct != null)
        {
            if (ct.equals(Integer.TYPE))
                pixels = (int[])p;
            else if (ct.equals(Byte.TYPE))
                throw new IllegalStateException("int[] of pixels expected, received byte[] instead.");
        }
    }
}
ImageUtils.java 文件源码 项目:openbd-core 阅读 32 收藏 0 点赞 0 评论 0
/**
    * Cretae a BufferedImage from an ImageProducer.
    * @param producer the ImageProducer
    * @return a new TYPE_INT_ARGB BufferedImage
    */
   public static BufferedImage createImage(ImageProducer producer) {
    PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new RuntimeException("Image fetch interrupted");
    }
    if ((pg.status() & ImageObserver.ABORT) != 0)
        throw new RuntimeException("Image fetch aborted");
    if ((pg.status() & ImageObserver.ERROR) != 0)
        throw new RuntimeException("Image fetch error");
    BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
    p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
    return p;
}


问题


面经


文章

微信
公众号

扫码关注公众号