当前位置: 首页>>代码示例>>Java>>正文


Java BufferedImage.getRGB方法代码示例

本文整理汇总了Java中java.awt.image.BufferedImage.getRGB方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.getRGB方法的具体用法?Java BufferedImage.getRGB怎么用?Java BufferedImage.getRGB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.BufferedImage的用法示例。


在下文中一共展示了BufferedImage.getRGB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: captureImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage captureImage(String iii) {
    try {
        Rectangle rec = new Rectangle(CAPTURE_1_X, CAPTURE_1_Y, CAPTURE_2_X, CAPTURE_2_Y);
        Robot robot = new Robot();
        
        BufferedImage img = robot.createScreenCapture(rec);
        
        int[] rawData = new int[DesktopScreenRecorder.FRAME_SIZE];

        img.getRGB(0, 0,
                DesktopScreenRecorder.CAPTURE_2_X,
                DesktopScreenRecorder.CAPTURE_2_Y,
                rawData,
                0,
                DesktopScreenRecorder.CAPTURE_2_X);
        
        return img;
    } catch (Exception e) {
        UIUtils.popupError(e, "ImageUtils::writeImage");
    }
    return null;
}
 
开发者ID:mhusam,项目名称:ChessBot,代码行数:23,代码来源:ImageUtils.java

示例2: enlargeImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Increases image.
 *
 * @param image an image to enlarge.
 * @param zoom A scale.
 * @return a result image.
 */
public static BufferedImage enlargeImage(BufferedImage image, int zoom) {
    int wight = image.getWidth();
    int height = image.getHeight();
    BufferedImage result = new BufferedImage(wight * zoom,
            height * zoom,
            image.getType());
    int rgb;
    for (int x = 0; x < wight; x++) {
        for (int y = 0; y < height; y++) {
            rgb = image.getRGB(x, y);
            for (int i = 0; i < zoom; i++) {
                for (int j = 0; j < zoom; j++) {
                    result.setRGB(x * zoom + i,
                            y * zoom + j,
                            rgb);
                }
            }
        }
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ImageTool.java

示例3: checkTestImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private void checkTestImage(BufferedImage dst) {
    // NB: do not forget about subsampling factor.
    int x = dx / (2 * srcXSubsampling);
    int y = h / (2 * srcYSubsampling);
    System.out.println("Check result: width=" + dst.getWidth() +
        ", height=" + dst.getHeight());
    for (int i = 0; i < colors.length; i++) {
        System.out.println("\tcheck at: " + x + ", " + y);
        int srcRgb = colors[i].getRGB();
        int dstRgb = dst.getRGB(x, y);
        if (srcRgb != dstRgb) {
            throw new RuntimeException("Test failed due to wrong dst color " +
                Integer.toHexString(dstRgb) + " at " + x + "," + y +
                "instead of " + Integer.toHexString(srcRgb));
        }
        x += dx / srcXSubsampling;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:BMPSubsamplingTest.java

示例4: getImageData

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static int[] getImageData(Image image) {
    int width = image.getWidth(null);
    int height = image.getHeight(null);
    BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = bimage.createGraphics();
    try {
        g2d.drawImage(image, 0, 0, width, height, null);
    } finally {
        g2d.dispose();
    }
    return bimage.getRGB(0, 0, width, height, null, 0, width);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:ImageTransferTest.java

示例5: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(final String[] args) {

        final BufferedImage bi = createBufferedImage();
        final VolatileImage vi = createVolatileImage();
        final Graphics s2dVi = vi.getGraphics();

        //sw->texture->surface blit
        s2dVi.drawImage(bi, 0, 0, null);

        final BufferedImage results = vi.getSnapshot();
        for (int i = 0; i < SIZE; ++i) {
            for (int j = 0; j < SIZE; ++j) {
                //Image should be opaque: (black color and alpha = 255)
                if (results.getRGB(i, j) != 0xFF000000) {
                    throw new RuntimeException("Failed: Wrong alpha");
                }
            }
        }
        System.out.println("Passed");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:bug7181438.java

示例6: compareBufferedImages

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Compares two bufferedImages pixel-by-pixel.
 * return true if all pixels in the two areas are identical
 */
public static boolean compareBufferedImages(BufferedImage bufferedImage0, BufferedImage bufferedImage1) {
    int width = bufferedImage0.getWidth();
    int height = bufferedImage0.getHeight();

    if (width != bufferedImage1.getWidth() || height != bufferedImage1.getHeight()) {
        return false;
    }

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (bufferedImage0.getRGB(x, y) != bufferedImage1.getRGB(x, y)) {
                return false;
            }
        }
    }

    return true;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:Util.java

示例7: checkColors

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Checks an image color. RED and GREEN are allowed only.
 */
private static void checkColors(final BufferedImage bi1,
                                final BufferedImage bi2)
        throws IOException {
    for (int i = 0; i < SIZE; ++i) {
        for (int j = 0; j < SIZE; ++j) {
            final int rgb1 = bi1.getRGB(i, j);
            final int rgb2 = bi2.getRGB(i, j);
            if (rgb1 != rgb2 || rgb1 != 0xFFFF0000 && rgb1 != 0xFF00FF00) {
                ImageIO.write(bi1, "png", new File("image1.png"));
                ImageIO.write(bi2, "png", new File("image2.png"));
                throw new RuntimeException("Failed: wrong text location");
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DrawRotatedStringUsingRotatedFont.java

示例8: loadNSMap1

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void loadNSMap1(IResourceManager manager, ResourceLocation location, int width, int height, int[] aint, int offset, int defaultColor)
{
    boolean flag = false;

    try
    {
        IResource iresource = manager.getResource(location);
        BufferedImage bufferedimage = ImageIO.read(iresource.getInputStream());

        if (bufferedimage != null && bufferedimage.getWidth() == width && bufferedimage.getHeight() == height)
        {
            bufferedimage.getRGB(0, 0, width, height, aint, offset, width);
            flag = true;
        }
    }
    catch (IOException var10)
    {
        ;
    }

    if (!flag)
    {
        Arrays.fill(aint, offset, offset + width * height, defaultColor);
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:26,代码来源:ShadersTex.java

示例9: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(final String[] args) {
    final GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi =
            gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);

    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                             RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();

        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:IncorrectAlphaConversionBicubic.java

示例10: checkFrame

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
protected void checkFrame(int i, BufferedImage f) {
    int x = 2 * i + 1;
    for (int y = 0; y < h; y++) {
        int argb = f.getRGB(x, y);
        if (argb != 0xffffffff && !(argb == 0xff0000ff && y == 2 * i)) {
            throw new RuntimeException("Test failed - bad frame");
        }
        argb = f.getRGB(y, x);
        if (argb != 0xffffffff && !(argb == 0xffff0000 && y == 2 * i)) {
            throw new RuntimeException("Test failed - bad frame");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AnimationTest.java

示例11: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(String[] args) {

        /* Create an image to draw, filled in solid red. */
        BufferedImage srcImg =
             new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
        Graphics srcG = srcImg.createGraphics();
        srcG.setColor(Color.red);
        int w = srcImg.getWidth(null);
        int h = srcImg.getHeight(null);
        srcG.fillRect(0, 0, w, h);

        /* Create a destination image */
        BufferedImage dstImage =
           new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
        Graphics2D dstG = dstImage.createGraphics();
        /* draw image under a scaling transform that overflows int */
        AffineTransform tx = new AffineTransform(0.5, 0, 0, 0.5,
                                                  0, 5.8658460197478485E9);
        dstG.setTransform(tx);
        dstG.drawImage(srcImg, 0, 0, null );
        /* draw image under the same overflowing transform, cancelling
         * out the 0.5 scale on the graphics
         */
        dstG.drawImage(srcImg, 0, 0, 2*w, 2*h, null);
        if (Color.red.getRGB() == dstImage.getRGB(w/2, h/2)) {
             throw new RuntimeException("Unexpected color: clipping failed.");
        }
        System.out.println("Test Thread Completed");
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:DrawImageCoordsTest.java

示例12: readIconImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static ByteBuffer readIconImage(File p_readIconImage_0_) throws IOException
{
    BufferedImage bufferedimage = ImageIO.read(p_readIconImage_0_);
    int[] aint = bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), (int[])null, 0, bufferedimage.getWidth());
    ByteBuffer bytebuffer = ByteBuffer.allocate(4 * aint.length);

    for (int i : aint)
    {
        bytebuffer.putInt(i << 8 | i >> 24 & 255);
    }

    bytebuffer.flip();
    return bytebuffer;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:15,代码来源:Config.java

示例13: lineFill

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
protected void lineFill(BufferedImage img, int x0, int x1, int y) {

		int c = img.getRGB(x0, y);	

		for(int x = x0+1; x <= x1; x++) {
			img.setRGB(x, y, c);
		}
	}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:9,代码来源:PixelSortFilter.java

示例14: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
  Graphics2D g = image.createGraphics();

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setPaint(Color.WHITE);
  g.fill(new Rectangle(image.getWidth(), image.getHeight()));

  g.scale(0.5 / PIXEL, 0.5 / PIXEL);
  g.setPaint(Color.BLACK);
  g.setStroke(new BasicStroke(PIXEL));
  g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));

  // To visually check it
  //ImageIO.write(image, "PNG", new File(args[0]));

  boolean nonWhitePixelFound = false;
  for (int x = 0; x < 200; ++x) {
    if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
      nonWhitePixelFound = true;
      break;
    }
  }
  if (!nonWhitePixelFound) {
    throw new RuntimeException("The thin line disappeared.");
  }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:ThinLineTest.java

示例15: checkBI

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private void checkBI(BufferedImage bi) {
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            if (bi.getRGB(x, y) == Color.blue.getRGB()) {
                try {
                    String fileName = "TransformedPaintTest_res.png";
                    ImageIO.write(bi, "png", new File(fileName));
                    System.err.println("Dumped image to: " + fileName);
                } catch (IOException ex) {}
                throw new RuntimeException("Test failed, blue color found");
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:TransformedPaintTest.java


注:本文中的java.awt.image.BufferedImage.getRGB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。