【问题标题】:Cropping an image to be bigger [closed]将图像裁剪为更大[关闭]
【发布时间】:2016-03-23 16:31:42
【问题描述】:

是否有可用于将图像裁剪得更大的 java 库或(任何库)? 问题是:任何纵横比的图像都必须以 16:9 呈现。 由于缩放会扭曲图像,我们需要呈现整个图像(所以我们无法裁剪) 解决方案是以某种方式将该图像叠加到白色背景上,其中背景是调整宽高比的背景。 或者简单地说:“将图像裁剪得更大”。 如何实际做到这一点?有没有一种使用标准 java 或库的巧妙方法来做到这一点?

【问题讨论】:

  • 如果你给我们一些代码来处理会更好。图像现在是什么形式(类)?

标签: java image crop aspect-ratio


【解决方案1】:

我不知道有这样的图书馆。

基本算法是:

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

如果你给我们你的代码尝试,有人可以把算法变成工作代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-31
    • 2011-12-15
    • 2015-12-08
    • 2023-03-10
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    相关资源
    最近更新 更多