java - 将图像裁剪得更大

标签 java image crop aspect-ratio

是否有 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/

相关文章:

ios - 如何裁剪 UIImage 中的中心正方形?

java - Jsoup 选择并替换多个 <a> 元素

java - 从流中获取最后 n 个元素

java - 如何在网站上显示Google Drive中的word文档?

asp.net - 容器中显示的图像 - 如何缩小和保持纵横比

java - 从字节数组转换和显示图像

c++ - 在Windows 8.1中使用OpenCV在C++中加载图像需要很长时间

html - CSS - 如何将图像裁剪成正方形,如果它已经是正方形然后调整它的大小

php - Ajax 或 jquery 客户端裁剪和调整大小库,通过 http 请求将裁剪后的文件发送到服务器

java - 具有两个方法参数的访问者模式