本文整理匯總了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");
}