【发布时间】:2014-11-20 16:59:24
【问题描述】:
我无法将图像旋转 90 度,图像为 768 x 768 像素。我在这里显示的代码能够创建一个新图像,但我编写的函数根本没有操作它。我在驱动程序中旋转它的图像类和函数在下面。我必须将所有图片顺时针和逆时针旋转 90 度;我认为我的问题是试图让指针正确切换像素。
class image {
public:
image(); //the image constructor (initializes everything)
image(string filename); //a image constructor that directly loads an image from disk
image(image &other); //copy constructor
~image(); //the image destructor (deletes the dynamically created pixel array)
pixel** getPixels(); //return the 2-dimensional pixels array
int getWidth(); //return the width of the image
int getHeight(); //return the height of the image
void createNewImage(int width, int height);
private:
pixel** pixels; // pixel data array for image
int width, height; // stores the image dimensions
void pixelsToCImage(CImage* myImage);
};
void RotateClockWise(image *imageIn)
{
image rotateImg;
image *ptr = (image*) &rotateImg;
*ptr = *imageIn;
int height = rotateImg.getHeight();
int width = rotateImg.getWidth();
pixel** rotatePix = rotateImg.getPixels();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
rotatePix[i][j] = rotatePix[j][i];
*(ptr + j * height + (height - i - 1)) = *(ptr + i * width + j);
}
}
}
【问题讨论】:
标签: c++ image visual-studio-2010 class rotation