c/c++将 8 bit 灰度图快速旋转90度
时间: 2024-02-24 08:54:03 浏览: 119
下面是一个使用C++的示例代码,可以快速地将一个8 bit灰度图像旋转90度:
```c++
#include <iostream>
#include <vector>
using namespace std;
void rotateImage(vector<unsigned char>& image, int width, int height) {
vector<unsigned char> tempImage(image.size());
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
tempImage[(width - 1 - j) * height + i] = image[i * width + j];
}
}
image = tempImage;
}
int main() {
// 假设我们有一张8 bit灰度图像,大小为 512x512
vector<unsigned char> image(512 * 512);
int width = 512;
int height = 512;
// 将图像旋转90度
rotateImage(image, width, height);
// 处理旋转后的图像
// ...
return 0;
}
```
这段代码使用了一个临时的图像数组tempImage,将旋转后的像素值保存在其中,最后再将tempImage数组赋值给原始的图像数组image。
阅读全文
相关推荐















