是否有 java 库或(任何库)可用于将图像裁剪得更大? 问题是:任何长宽比的图像都必须以 16:9 的形式呈现。 由于缩放会扭曲图像,并且我们需要呈现整个图像(因此我们无法裁剪) 解决方案是以某种方式将该图像叠加到白色背景上,其中背景将调整纵横比。 或者简单地用其他术语来说:“将图像裁剪得更大”。 实际上如何做到这一点?有没有一种巧妙的方法可以使用标准 java 或库来做到这一点?
最佳答案
我不知道有这样的库。
基本算法是:
1) if aspect ratio > 16/9
Create a new image buffer that is taller than the original but
same width and aspect ratio 16/9
blat the image with a background (like white)
draw the original into the buffer at right position.
2) if aspect ratio = 16/9, do nothing
3) if aspect ratio < 16/9
Create a new image buffer that is wider than the original but
same height and aspect ratio of 16/9
blat the image with background (like white)
draw the original into buffer at right position
如果您尝试编写代码,有人可以将算法转化为工作代码。
关于java - 将图像裁剪得更大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34330646/