我试图将一个bmp图像顺时针旋转90度。但是,我被卡住了。我只能旋转180度。下面是我的180度旋转代码
int row_size = ((width * 3 + 3) / 4) * 4;
uint8_t* pixels = (uint8_t*)malloc(height * row_size);
fread(pixels, sizeof(uint8_t), height * row_size, input);
uint8_t* rotatedPixels = (uint8_t*)malloc(height * row_size);
for (uint32_t i = 0; i < width; ++i) {
for (uint32_t j = 0; j < height; ++j) {
uint32_t new_i = height - 1 - j;
uint32_t new_j = width - 1 - i;
rotatedPixels[(new_i * row_size) + (new_j * 3)] = pixels[(j * row_size) + (i * 3)];
rotatedPixels[(new_i * row_size) + (new_j * 3) + 1] = pixels[(j * row_size) + (i * 3) + 1];
rotatedPixels[(new_i * row_size) + (new_j * 3) + 2] = pixels[(j * row_size) + (i * 3) + 2];
}
}
fwrite(header, sizeof(uint8_t), 54, output);
fwrite(rotatedPixels, sizeof(uint8_t), height * row_size, output);
free(pixels);
free(rotatedPixels);
}
字符串
1条答案
按热度按时间tzcvj98z1#
字符串