Java Code Examples for java.awt.image.BufferedImage.TYPE_INT_RGB

The following are Jave code examples for showing how to use TYPE_INT_RGB of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: parabuild-ci   File: AreaChartTests.java   View Source Code Vote up 6 votes
/**
 * Draws the chart with a null info object to make sure that no exceptions 
 * are thrown (a problem that was occurring at one point).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, 
                null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example 2
Project: incubator-netbeans   File: MultiViewTopComponentTest.java   View Source Code Vote up 6 votes
/** Tests that multiple instances of the same class propagate well
 * into array of actions of enclosing multiview TopComponent
 */
public void testFix_204072_MissingIcon() {
    final Image img = new BufferedImage( 10, 10, BufferedImage.TYPE_INT_RGB );
    MVElem elem1 = new MVElem();
    MVElem elem2 = new MVElem();
    MultiViewDescription desc1 = new MVDesc("desc1", img, 0, elem1);
    MultiViewDescription desc2 = new MVDesc("desc2", null, 0, elem2);
    TopComponent tc = MultiViewFactory.createMultiView(new MultiViewDescription[] { desc1, desc2 }, desc1);

    tc.open();
    tc.requestActive();
    
    assertEquals( img, tc.getIcon() );
    
    MultiViewTopComponent mvtc = ( MultiViewTopComponent ) tc;
    mvtc.getModel().setActiveDescription( desc2 );
    
    assertEquals( img, tc.getIcon() );
}
 
Example 3
Project: openjdk-jdk10   File: bug8134721.java   View Source Code Vote up 6 votes
private static void testNPE() {

        Graphics g = null;
        try {
            String test = "\ttest\ttest2";
            BufferedImage buffImage = new BufferedImage(
                    100, 100, BufferedImage.TYPE_INT_RGB);
            g = buffImage.createGraphics();
            Segment segment = new Segment(test.toCharArray(), 0, test.length());
            Utilities.drawTabbedText(segment, 0, 0, g, null, 0);
        } finally {
            if (g != null) {
                g.dispose();
            }
        }
    }
 
Example 4
Project: opencron   File: ImageUtils.java   View Source Code Vote up 6 votes
public ImageUtils reverse(boolean isVertical){
    int width = this.dealedImage.getWidth();
    int height = this.dealedImage.getHeight();
    double[] matrix;
    if(isVertical){
        matrix = new double[]{1, 0, 0, -1, 0,height};
    }else {
        matrix = new double[]{-1, 0, 0, 1,width,0};
    }
    AffineTransform affineTransform = new AffineTransform(matrix);
    BufferedImage newImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = newImg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawRenderedImage(this.dealedImage, affineTransform);
    g.dispose();
    this.dealedImage = newImg;

    return this;
}
 
Example 5
Project: pacman-mas   File: BoardGui.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g)
{
    // Gets the canvas to draw in
    BufferedImage bi = new BufferedImage(
        Constant.BOARD_CELL_SIZE * board.countColumns(),
        Constant.BOARD_CELL_SIZE * board.countRows(),
        BufferedImage.TYPE_INT_RGB
    );
    
    Graphics2D canvas = bi.createGraphics();

    // Draws the game in the canvas
    for (int i = 0; i < board.countRows(); ++i)
    {
        for (int j = 0; j < board.countColumns(); ++j)
        {
            board.getCell(new Coord2D(i, j)).draw(canvas);
        }
    }
    
    // Really paints the component
    ((Graphics2D) g).drawImage(bi, 0, 0, this);
}
 
Example 6
Project: jdk8u-jdk   File: DrawRotatedString.java   View Source Code Vote up 6 votes
private static BufferedImage createBufferedImage(final boolean  aa) {
    final BufferedImage bi = new BufferedImage(SIZE, SIZE,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D bg = bi.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        aa ? RenderingHints.VALUE_ANTIALIAS_ON
                           : RenderingHints.VALUE_ANTIALIAS_OFF);
    bg.setColor(Color.RED);
    bg.fillRect(0, 0, SIZE, SIZE);
    bg.translate(100, 100);
    bg.rotate(Math.toRadians(90));
    bg.setColor(Color.BLACK);
    bg.setFont(bg.getFont().deriveFont(20.0f));
    bg.drawString("MMMMMMMMMMMMMMMM", 0, 0);
    bg.dispose();
    return bi;
}
 
Example 7
Project: parabuild-ci   File: BarChartTests.java   View Source Code Vote up 6 votes
/**
 * Draws the chart with a null info object to make sure that no exceptions 
 * are thrown (a problem that was occurring at one point).
 */
public void testDrawWithNullInfo() {

    boolean success = false;

    try {
        BufferedImage image = new BufferedImage(200 , 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, 
                null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }

    assertTrue(success);

}
 
Example 8
Project: openjdk-jdk10   File: RenderToCustomBufferTest.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    final BufferedImage dst_custom = createCustomBuffer();
    final BufferedImage dst_dcm = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);

    renderTo(dst_custom);
    renderTo(dst_dcm);

    check(dst_custom, dst_dcm);
}
 
Example 9
Project: jdk8u-jdk   File: TranslatedOutlineTest.java   View Source Code Vote up 5 votes
public static void main(String a[]) {
    /* prepare blank image */
    BufferedImage bi = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) bi.getGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, 50, 50);

    /* draw outline somethere in the middle of the image */
    FontRenderContext frc = new FontRenderContext(null, false, false);
    g2.setColor(Color.RED);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    GlyphVector gv = g2.getFont().createGlyphVector(frc, "test");
    g2.fill(gv.getOutline(20, 20));

    /* Check if anything was drawn.
     * If y direction is not correct then image is still blank and
     * test will fail.
     */
    int bgcolor = Color.WHITE.getRGB();
    for (int i=0; i<bi.getWidth(); i++) {
        for(int j=0; j<bi.getHeight(); j++) {
           if (bi.getRGB(i, j) != bgcolor) {
               System.out.println("Test passed.");
               return;
           }
        }
    }
    throw new RuntimeException("Outline was not detected");
}
 
Example 10
Project: teasy   File: CombinedImage.java   View Source Code Vote up 5 votes
private BufferedImage combine(BufferedImage etalonImage, BufferedImage actualImage) {
    // create the new image, canvas size is the max. of both image sizes
    int w = etalonImage.getWidth() + actualImage.getWidth() + 1;
    int h = Math.max(etalonImage.getHeight(), actualImage.getHeight());
    BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

    // paint both images, preserving the alpha channels
    Graphics g = combined.getGraphics();
    g.drawImage(etalonImage, 0, 0, null);
    g.drawImage(actualImage, etalonImage.getWidth() + 1, 0, null);
    return combined;
}
 
Example 11
Project: cv4j-desktop   File: CV4JImage.java   View Source Code Vote up 5 votes
/**
 * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance
 * penalty of BufferedImage.setRGB unmanaging the image.
 */
public static void setRGB( BufferedImage image, int x, int y, int width, int height, int[] pixels ) {
	int type = image.getType();
	if ( type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB )
		image.getRaster().setDataElements( x, y, width, height, pixels );
	else
		image.setRGB( x, y, width, height, pixels, 0, width );
   }
 
Example 12
Project: CoverageGA   File: GeneticAlgorithmUtility.java   View Source Code Vote up 5 votes
public void initImage(final Graphics2D _g2d) {
	if (_g2d == null) {
		image = new BufferedImage(SensorInfo.getInstance().parameter.getAreaWidth(),
				SensorInfo.getInstance().parameter.getAreaHeight(), BufferedImage.TYPE_INT_RGB);
		g2d = image.createGraphics();
	} else {
		g2d = _g2d;
	}
}
 
Example 13
Project: openjdk-jdk10   File: WriterResetTest.java   View Source Code Vote up 5 votes
private static BufferedImage createTestImage() {
    BufferedImage img = new BufferedImage(100, 100,
                                          BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, 100, 100);
    g.setColor(Color.black);
    g.fillRect(20, 20, 60, 60);

    return img;
}
 
Example 14
Project: openjdk-jdk10   File: ReaderListenersTest.java   View Source Code Vote up 5 votes
protected static BufferedImage createTestImage() {
    BufferedImage res = new BufferedImage(100, 100,
                                          BufferedImage.TYPE_INT_RGB);
    Graphics2D g = res.createGraphics();
    g.setColor(Color.red);
    g.fillRect(0,0, 100,100);
    return res;
}
 
Example 15
Project: OpenJSharp   File: ImageDataContentHandler.java   View Source Code Vote up 5 votes
private BufferedImage render(Image img) throws InterruptedException {

        MediaTracker tracker = new MediaTracker(this);
        tracker.addImage(img, 0);
        tracker.waitForAll();
        BufferedImage bufImage = new BufferedImage(img.getWidth(null),
            img.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics g = bufImage.createGraphics();
        g.drawImage(img, 0, 0, null);
        g.dispose();
        return bufImage;
    }
 
Example 16
Project: openjdk-jdk10   File: MultiResolutionDisabledImageTest.java   View Source Code Vote up 5 votes
private static BufferedImage createImage(int scale) throws Exception {
    BufferedImage image = new BufferedImage(scale * 200, scale * 300,
                                            BufferedImage.TYPE_INT_RGB);
    Graphics g = image.createGraphics();
    g.setColor(scale == 1 ? COLOR_1X : COLOR_2X);
    g.fillRect(0, 0, scale * 200, scale * 300);
    g.dispose();
    return image;
}
 
Example 17
Project: openjdk-jdk10   File: PgramUserBoundsTest.java   View Source Code Vote up 5 votes
public static void main(String argv[]) {
    BufferedImage bimg =
        new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bimg.createGraphics();
    g2d.setPaint(new BoundsCheckerPaint(MinX, MinY, MaxX, MaxY));
    testAll(g2d);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);
    testAll(g2d);
}
 
Example 18
Project: openjdk-jdk10   File: ThinLineTest.java   View Source Code Vote up 5 votes
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.");
  }
}
 
Example 19
Project: rapidminer   File: SingleResultOverview.java   View Source Code Vote up 4 votes
/**
 * Updates the preview renderable image in a {@link SwingWorker}.
 */
private void updatePreviewImage() {
	final IOObject result = ioObject.get();
	if (result != null) {
		String name = RendererService.getName(result.getClass());
		final List<Renderer> renderers = RendererService.getRenderers(name);
		if (renderers.isEmpty()) {
			return;
		}

		SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() throws Exception {
				int width = Math.max(getSize().width, MIN_WIDTH);
				int height = Math.max(getSize().height, MIN_HEIGHT);
				for (Renderer renderer : renderers) {
					Reportable reportable = renderer.createReportable(result, new IOContainer(), 800, 600);
					if (reportable instanceof Renderable) {
						Renderable renderable = (Renderable) reportable;
						renderable.prepareRendering();
						int preferredWidth = renderable.getRenderWidth(800);
						int preferredHeight = renderable.getRenderHeight(600);

						img = new BufferedImage(preferredWidth, preferredHeight, BufferedImage.TYPE_INT_RGB);
						Graphics2D graphics = (Graphics2D) img.getGraphics();
						graphics.setColor(Colors.WHITE);
						graphics.fillRect(0, 0, 5000, 3000);
						double scale = Math.min((double) width / (double) preferredWidth, (double) height
								/ (double) preferredHeight);
						graphics.scale(scale, scale);
						renderable.render(graphics, preferredWidth, preferredHeight);

						break;
					}
				}

				return null;
			}

			@Override
			public void done() {
				main.repaint();
			}
		};
		sw.execute();
	}
}
 
Example 20
Project: jdk8u-jdk   File: ImageTypeSpecifier.java   View Source Code Vote up 3 votes
/**
 * Returns an <code>ImageTypeSpecifier</code> that encodes
 * one of the standard <code>BufferedImage</code> types
 * (other than <code>TYPE_CUSTOM</code>).
 *
 * @param bufferedImageType an int representing one of the standard
 * <code>BufferedImage</code> types.
 *
 * @return an <code>ImageTypeSpecifier</code> with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if
 * <code>bufferedImageType</code> is not one of the standard
 * types, or is equal to <code>TYPE_CUSTOM</code>.
 *
 * @see java.awt.image.BufferedImage
 * @see java.awt.image.BufferedImage#TYPE_INT_RGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
 * @see java.awt.image.BufferedImage#TYPE_INT_BGR
 * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
 * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
 * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
 * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
 * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
 */
public static
    ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
    if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
        bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
        return getSpecifier(bufferedImageType);
    } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
        throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
    } else {
        throw new IllegalArgumentException("Invalid BufferedImage type!");
    }
}