I use Thumbnailator to convert images from png to jpg and then resize them:
Thumbnails.of(new File("C:/279.png"))
.outputFormat("JPG")
.size(100, 100)
.outputQuality(1.0)
.toFile(new File("C:/279.jpg"));
Original image has transparent background, but output image has black background. How to set white background on output image?
Thank you.
Solution:
Use .addFilter(new Canvas(100, 100, Positions.CENTER, Color.WHITE))
Example:
Thumbnails.of(new File("C:/279.png"))
.outputFormat("JPG")
.size(100, 100)
.addFilter(new Canvas(100, 100, Positions.CENTER, Color.WHITE))
.outputQuality(1.0)
.toFile(new File("C:/279.jpg"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.