Java Code Examples for java.awt.Rectangle#intersect()
The following examples show how to use
java.awt.Rectangle#intersect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceClippingBlitTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 2
Source File: SourceClippingBlitTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 3
Source File: SourceClippingBlitTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 4
Source File: SourceClippingBlitTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 5
Source File: SourceClippingBlitTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 6
Source File: SourceClippingBlitTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 7
Source File: SourceClippingBlitTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 8
Source File: SourceClippingBlitTest.java From hottub with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 9
Source File: SourceClippingBlitTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 10
Source File: SourceClippingBlitTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 11
Source File: SourceClippingBlitTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 12
Source File: SourceClippingBlitTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }
Example 13
Source File: SourceClippingBlitTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public void test(Rectangle srcRect, Rectangle dstRect) { int w = getWidth(); int h = getHeight(); Toolkit.getDefaultToolkit().sync(); try { Thread.sleep(2000); } catch (InterruptedException ex) {} Point p = getLocationOnScreen(); grabbedBI = robot.createScreenCapture(new Rectangle(p.x, p.y, w, h)); // calculate the destination rectangle Rectangle srcBounds = srcRect.intersection(IMAGE_BOUNDS); int trX = dstRect.x - srcRect.x; int trY = dstRect.y - srcRect.y; Rectangle newDstRect = (Rectangle)dstRect.clone(); newDstRect.translate(-trX, -trY); Rectangle.intersect(newDstRect, srcBounds, newDstRect); newDstRect.translate(trX, trY); Rectangle.intersect(newDstRect, new Rectangle(0, 0, w, h), newDstRect); System.out.println("calculated dest rect:" + newDstRect); // we do implicit clipping of the destination surface // by only checking pixels within its bounds for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int rgb = 0; if (newDstRect.contains(x, y)) { rgb = Color.red.getRGB(); } else { rgb = Color.green.getRGB(); } if (grabbedBI.getRGB(x, y) != rgb) { String msg1 = "Test failed at x="+x+" y="+y; System.out.println(msg1); System.out.println(" expected: "+Integer.toHexString(rgb)+ " got:"+Integer.toHexString(grabbedBI.getRGB(x, y))); throw new RuntimeException(msg1); } } } System.out.println("subtest passed"); }