0

好的,我正在研究一种放大 bmp 文件的方法,但我对如何去做有点困惑。这就是我认为放大的方式:

假设我们有 bmp 文件:

0 1 2
3 4 5

一个 3x2 2D 数组,假设我们想将该图像放大 2 倍,那么新图像将如下所示:

0 0 1 1 2 2
0 0 1 1 2 2
3 3 4 4 5 5
3 3 4 4 5 5

我对此是正确的还是它以不同的方式工作?
谢谢,我只需要了解编写算法的工作原理。

4

1 回答 1

1

我基本上称这种图像调整大小方法为:“brute sizing”或“image scaling”

  1. 尺寸计算:

    原始图像尺寸: 3 x 2 像素(共 6 像素)

    如果您将高度缩放 ​​2 并将宽度缩放 2

    最终图像尺寸: 6 x 4 像素(共 24 像素)

  2. 执行:

    这是一个例子:
    假设: AA =3,AB =2,AC =6 BA =6,BB =4,BC =24 scaleX =2,scaleY =2


    int ptotal = AC; //or = AA * AB

    for (pcount = 0; pcount < ptotal; ++pcount)
    {
        img_x = (pcount%(AA))*scaleX;
        if ((pcount%(scaleX))==0)
            img_y += scaleY;
        set_rect_BMP(bmp,img_x,img_y,scaleX,scaleY,r,g,b);
    }

int set_rect_BMP(BMP* bmp, int x, int y, int w, int h, int r, int g, int b) {

    int i, j;
    for (i = y; i < h+y; ++i)
    {
        for (j = x; j < w+x; ++j)
        {
            BMP_SetPixelRGB( bmp, j, i, r, g, b );
            //BMP_SetPixelRGB( bmp, the x coord, the y coord, red, green, blue );
        }
    }
}

算法示意图:

在此处输入图像描述


如果需要,将给出进一步的解释;)在这里查看更多关于维基百科的信息:http ://en.wikipedia.org/wiki/Image_scaling

于 2013-10-26T04:59:20.597 回答