如何调整位图 [英] How to resize a bitmap

查看:176
本文介绍了如何调整位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    // determine padding for scanlines
int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    for(int q = 0; q < n; q++)
    {
        // iterate over pixels in scanline
        for (int j = 0; j < bi.biWidth; j++)
        {
            // temporary storage
            RGBTRIPLE triple;

            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

            // write RGB triple to outfile
            for (int r = 0; r < n; r++)
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

        }

    // skip over padding, if any
    fseek(inptr, padding, SEEK_CUR);

    //then add it back (to demonstrate how)
    for (int k = 0; k < padding; k++)
        fputc(0x00, outptr);
   }
}

我想改变code,这样我可以用n倍调整为BMP(加入正三倍的宽度和高度)。我已经找到一种方法来遍历一个for循环,将调整宽度:为(INT R = 0; R&LT; N,R ++)。我试图做随高度同样的事情,我想不通为什么它不会工作。 为(INT Q = 0; Q&LT; N,Q ++)

I'm trying to alter code so that I can resize a bmp by a factor of n (adding n triples to the the width and the height). I have found a way to iterate a for loop that will resize the width: for (int r = 0; r < n; r++). I tried to do the same thing with height and I can't figure out why it won't work. for (int q = 0; q < n; q++)

推荐答案

目前,你应该经过一个像素的单个读做 N 的写入线路电平。这是通过增加另一个内环完成。这种复制像素驻留在在操作过程中无功。

At the line level you should after single read of a pixel do n writes of it. This is done by adding another inner loop. That copied pixel resides at triple var during the operation.

在文件级别,你应该重复处理单行,读,多次写它。

At the file level you should repeatedly process single line, reading and writing it multiple times.

如果您输入的文件在磁盘上,它应该支持复卷。所以,你可以读取行,写(内复制像素,如上图所示),再倒回文件到行的开始,再次读取该行,写等。

If your input file is on the disk, it should support rewinding. So you can read the line, write it (duplicating pixels inside, as shown above), then rewind the file to the start of the line, read the line again, write it, etc.

尝试存储与 FTELL 的文件位置读取前行,后退的文件位置这一点与 fseek的每次你需要处理它。

Try to store the file position with ftell before reading the line, and rewind the file position to this point with fseek each time you need to process it.

这篇关于如何调整位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆