当前位置: 首页>>代码示例>>Java>>正文


Java Rectangle.intersect方法代码示例

本文整理汇总了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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:44,代码来源:SourceClippingBlitTest.java


注:本文中的java.awt.Rectangle.intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。