即时通讯工作在这个任务和由于某种原因,它不复制所有行。它跳过bmp的某些行,所以它不会完全放大图片。 我会非常感谢一些反馈,为什么它这样做。 我知道它必须与指针算术相关。放大BMP未压缩
int enlarge(PIXEL* original, int rows, int cols, int scale,
PIXEL** new, int* newrows, int* newcols)
{
*newcols = cols * scale;
*newrows = rows * scale;
/* Allocate memory for enlarged bmp */
*new = (PIXEL*)malloc((*newrows)*(*newcols) * sizeof(PIXEL));
if(!*new)
{
free(*new);
fprintf(stderr, "Could not allocate memory.\n");
return 1;
}
int i,j,k,l;
int index = 0;
int counter = scale*rows;
PIXEL* o;
PIXEL* n;
for(i = 0; i < rows; i++)
{
for(j = 0; j < cols; j++)
{
for(k = 0; k < scale; k++)
{
o = original + (i*cols) + j;
index++;
for(l = 0; l < scale; l++)
{
n = (*new) + (i*cols*scale) + index + (counter*l);
*n = *o;
}
}
}
}
return 0;
}
一切都OK,直到你计算'n',那么你完全失去了我。我特别想知道'索引'。 –
索引帮助我指向下一个位置,其中原始值将位于我的新位图中 – Hous3aholik