使用C/C++对图像/矩阵向右旋转,具体的实现原理及步骤如下图所示:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int w = 4, h = 4;
int imgSize = w * h;
unsigned short *pImg = NULL;
unsigned short *pImgR = NULL;
pImg = new unsigned short[imgSize];
if(pImg != NULL)
{
memset(pImg, 0, sizeof(unsigned short) * imgSize);
}
pImgR = new unsigned short[imgSize];
if(pImgR != NULL)
{
memset(pImgR, 0, sizeof(unsigned short) * imgSize);
}
cout << "右旋前:" << endl;
for (int i = 0; i < h; i++) //行
{
for (int j = 0; j < w; j++) //列
{
pImg[j + i * w] = j + i * w;