我已经实现了一个在 c# 中垂直调整图像大小的函数(缩放)。它需要两个参数:要调整大小的图像和图像的新高度。这是我的代码:
  public static Bitmap ScaleUpDown(Bitmap b, int height)
    {
        Bitmap scaledImage = new Bitmap(b.Width, height);
        int scaleRatio = height / b.Height;
        if (scaleRatio >= 1)
        {
            for (int i = 0; i < b.Width; i++)
            {
                for (int j = 0; j < b.Height; j++)
                {
                    Color pixel = b.GetPixel(i, j);
                    int fill = 0;
                    while (fill < scaleRatio)
                    {
                        scaledImage.SetPixel(i, scaleRatio * j + fill, pixel);
                        fill++;
                    }
                }
            }
        }
        return scaledImage;
    }
这就是我所做的:我访问每个像素,将其复制并根据调整大小的比例将其粘贴到同一列或多列中的下一行。我的问题是,只有当新高度是旧高度的倍数时,此代码才能正常工作,例如 2*oldHeight、3*oldHeight 等。如果新高度应该是旧高度的 1.5 倍或 1.3 倍怎么办?我能做些什么呢?
谢谢