Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用thumbnailator旋转图像时如何设置背景色_Java_Image - Fatal编程技术网

Java 使用thumbnailator旋转图像时如何设置背景色

Java 使用thumbnailator旋转图像时如何设置背景色,java,image,Java,Image,我正在尝试使用库旋转图像。除了我看不到任何设置新图像背景色的方法外,它工作正常 Thumbnails.of(image).rotate(45).toByteArray() 如果我将图像旋转45度,它会使角变黑。如果我需要设置其他颜色,我该如何设置 具有黑色背景的旋转图像示例: 您可以转换为中间图像,然后应用背景色 这大部分是未经测试的 实际的图像对象是什么?它是一个缓冲图像吗?还是图像文件?如果是,图像的格式是什么?最后,您是如何创建在这个问题中发布的图像文件的?我需要这些提示来追踪到底发生了

我正在尝试使用库旋转图像。除了我看不到任何设置新图像背景色的方法外,它工作正常

Thumbnails.of(image).rotate(45).toByteArray()
如果我将图像旋转45度,它会使角变黑。如果我需要设置其他颜色,我该如何设置

具有黑色背景的旋转图像示例:


您可以转换为中间图像,然后应用背景色

这大部分是未经测试的


实际的图像对象是什么?它是一个缓冲图像吗?还是图像文件?如果是,图像的格式是什么?最后,您是如何创建在这个问题中发布的图像文件的?我需要这些提示来追踪到底发生了什么。我是Thumbnailator Library的作者图像是BuffereImage。生成图像的代码如下所示:Thumbnails.ofimage.size100,60.rotate45.imageTypeBuffereImage.TYPE_INT_ARGB.outputQuality0.8D.outputFormatjpeg.toByteArray;
Color newBackgroundColor = java.awt.Color.WHITE;

// apply your transformation, save as new BufferedImage
BufferedImage transImage = Thumbnails.of(image)
        .size(100, 60)
        .rotate(45)
        .outputQuality(0.8D)
        .outputFormat("jpeg")
        .asBufferedImage();

// Converts image to plain RGB format
BufferedImage newCompleteImage = new BufferedImage(transImage.getWidth(), transImage.getHeight(),
        BufferedImage.TYPE_INT_ARGB);
newCompleteImage.createGraphics().drawImage(transImage, 0, 0, newBackgroundColor, null);

// write the transformed image with the desired background color
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(newCompleteImage, "jpeg", baos);