C语言旋转图像

//顺时针旋转90度

int Rotate(unsigned char * data,int width,int height, int channel)
{
	unsigned char * tempdata = NULL;
	int Size = width * height * channel *sizeof(char);
	int i = 0;
	int j = 0;
	int k = 0;
	int desW = height;
	int desH = width;

	tempdata = (unsigned char *)malloc(sizeof(char) * width* height* channel);
	memcpy(tempdata , data, Size);

	for(i = 0; i < desH; i ++)
	{
		for(j = 0; j < desW; j ++)
		{
			for(k = 0; k < channel; k ++)
			{
				src[(i * desW + j) * channel + k] = tempdata [((height- 1 - j) * width+ i) * channel + k];
			}
		}
	}

	free(tempdata );
	return 0;

//旋转180度

int Rotate_Down(unsigned char * data,int width ,int height,int channel)
{
	unsigned char * tempdata = NULLl
	int Size = width * height * channel * sizeof(char);
	int i = 0;
	int j = 0;
	int k = 0;
	int desW = width;
	int desH = height;
	
	tempdata = (unsigned char *)malloc(sizeof(char) * width * height* channel);
	memcpy(tempdata , data, Size);

	for(i = 0; i < desH; i ++)
	{
		for(j = 0; j < desW; j ++)
		{
			for(k = 0; k < channel; k ++)
			{
				src[(i * desW + j) * channel + k] = tempdata [((height- 1 - i) * width + width - 1 - j) * channel + k];
			}
		}
	}	
	free(tempdata);
	return 0;
}

原文链接:https://blog.csdn.net/baidu_31872269/article/details/53229342

你可能感兴趣的:(c语言)