创建图像索引转换器

时间:2017-11-05 19:58:02

标签: java bufferedimage

方法toVertical,按以下顺序接受两个参数:

(a)BufferedImage类型的图像

(b)双重比例y坐标

它返回int作为图像中与比例对应的像素坐标 坐标。该比例反向应用于图像的高度,比例为0 映射到最下面一行像素(其索引比图像的高度小一个), 和比例1映射到顶行像素,其索引为0.此逆映射 具有将图像的原点置于比例空间中到左下角的效果 图片。

例如,如果图像的宽度为30,则应按不同比例生成以下值:

•toVertical(image30,0.0)→29

•toVertical(image30,1.0)→0

•toVertical(image30,0.75)→7

•toVertical(image30,0.77)→7

我对如何解决这个问题很困惑。     这是我到目前为止的代码。

public static int toVertical(BufferedImage image, double ycoor) {
    int height = image.getHeight(); 
    double prop = height * (1/ycoor);
    int prop1 = (int) ()
    return prop1 -+ 1;

1 个答案:

答案 0 :(得分:0)

如果你修改这样的功能,你应该得到所需的输出:

public static int toVertical(BufferedImage image, double ycoor) {
    int height = image.getHeight(); 
    double prop = (height - 1) - (height - 1)*ycoor;
    int prop1 = (int)prop;
    return prop1;

(height - 1)将为您提供BufferedImage的最大索引

相关问题