如何将 BufferedImage 转换为 javaxt.io.Image?

How to convert BufferedImage to javaxt.io.Image?

我需要使用 image.setCorners() 倾斜图像,这可以使用 JavaXT 库完成。 但是我有 BufferedImage 形式的图像而不是保存的文件。

那么如何将 BufferedImage 转换为 javaxt.io.Image 以便我可以对其执行倾斜操作。

这是我用来扭曲图像的代码:

javaxt.io.Image image = new javaxt.io.Image("image1.jpg");

System.out.println(image.getWidth() + "x" + image.getHeight());
int width = image.getWidth();
int height = image.getHeight();
image.setCorners(0, 0,             //UL
                 width, 10,        //UR
                 width, height-10, //LR
                 0, height);       //LL

javaxt.io.Image class 的构造函数如下:

public Image(java.awt.image.BufferedImage bufferedImage)

所以你可以这样做:

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