Java Code Examples for java.awt.Rectangle#intersect()
The following examples show how to use
java.awt.Rectangle#intersect() .
These examples are extracted from open source projects.
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 Project: dragonwell8_jdk File: SourceClippingBlitTest.java License: 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 Project: TencentKona-8 File: SourceClippingBlitTest.java License: 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 Project: jdk8u60 File: SourceClippingBlitTest.java License: 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 Project: openjdk-jdk8u File: SourceClippingBlitTest.java License: 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 Project: openjdk-jdk8u-backup File: SourceClippingBlitTest.java License: 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 Project: openjdk-jdk9 File: SourceClippingBlitTest.java License: 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 Project: jdk8u-jdk File: SourceClippingBlitTest.java License: 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 Project: hottub File: SourceClippingBlitTest.java License: 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 Project: openjdk-8-source File: SourceClippingBlitTest.java License: 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 Project: openjdk-8 File: SourceClippingBlitTest.java License: 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 Project: jdk8u_jdk File: SourceClippingBlitTest.java License: 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 Project: jdk8u-jdk File: SourceClippingBlitTest.java License: 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 Project: jdk8u-dev-jdk File: SourceClippingBlitTest.java License: 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"); }