本文整理汇总了Java中java.awt.Rectangle.intersect方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle.intersect方法的具体用法?Java Rectangle.intersect怎么用?Java Rectangle.intersect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Rectangle
的用法示例。
在下文中一共展示了Rectangle.intersect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.awt.Rectangle; //导入方法依赖的package包/类
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");
}