java - 倾斜缓冲图像 java

标签 java image-processing bufferedimage

我有一张图像,想要裁剪给定的角点。 例如

the normal image

我只想剪切数独谜题。我有角点 (x1, y1)、(x2, y2)、(x3, y3)、(x4, y4)。

尝试过这个:

javaxt.io.Image image = new javaxt.io.Image(bufferedImage);
    image.setCorners((float) pointTopLeft.getX(), (float) pointTopLeft.getY(),              //UL
            (float) pointTopRight.getX(), (float) pointTopRight.getY(),                     //UR
            (float) pointBottomRight.getX(), (float) pointBottomRight.getY(),               //LR
            (float) pointBottomLeft.getX(), (float) pointBottomLeft.getY());                //LL

但是它返回的结果是这样的(这不是我想要的): enter image description here

最佳答案

您可以首先通过移动底角和右上角来倾斜图像 - 这将产生更矩形的形状。然后您可以裁剪图像。

我尝试过这个:

    Image image = new javaxt.io.Image(bufferedImage);

    // skew image
    image.setCorners(
            // keep the upper left corner as it is
            0,0, // UL

            // push the upper right corner more to the bottom
            image.getWidth(),20, // UR

            // push the lower right corner more to the left
            image.getWidth()-45,image.getHeight(), // LR

            // push the lower left corner more to the right
            55,image.getHeight()); // LL

    // crop image
    image.crop(80, 105, image.getWidth()-150, image.getHeight()-105);

结果是这样的:

result image

希望这有帮助。

关于java - 倾斜缓冲图像 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28265767/

相关文章:

java - 如何在 pdf 链接上设置 favicon.ico?

android - 改进 Android 上的 Tesseract 结果

java - 如何从 Java 中的图形堆栈中删除以前的 BufferedImage?

java - 将二维像素数组转换为 BufferedImage

java - 图像绘制在错误的位置

java - 从外部 war 中读取 context.xml

java - 将一行文本转换为 int 值

java - 在 Java 中通过套接字发送图像的有效方法

c++ - 尝试在给定阈值处将所有像素更改为黑色和白色

java - 将 375x375 图像的网格拼接成一个