顺时针旋转图片90度(算法)
2015-03-11 13:10
316 查看
Give an image represented by an NxN matrix ,where each pixel in the image is 4 bytes,write a method to rotate the image by 90 degrees .Can you do this in place?
Once the exterior elements are rotated ,we then rotate the interior region's edges.
Once the exterior elements are rotated ,we then rotate the interior region's edges.
public static void rotate(int [][] matrix,int n) { for(int layer = 0; layer < n/2; layer ++) { int first = layer; int last = n-1-layer; for(int i = first; i < last; i++) { int offset = i - first; int top = matrix[first][i]; //left -> top matrix[first][i] = matrix[last-offset][first]; //bottom -> left matrix[last-offset][first] = matrix[last][last - offset]; //right -> bottom matrix[last][last - offset] = matrix[i][last]; //top -> right matrix[i][last] = top; } } }
相关文章推荐
- 图片顺时针旋转90度的算法
- 人人都来写算法 之 矩阵顺时针旋转90度,空间效率O(1),时间效率O(n*n)
- LeetCode -- 顺时针旋转图片90度
- 【重构】人人都来写算法 之 矩阵顺时针旋转90度,空间效率O(1),时间效率O(n*n)
- 有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度。
- OpenCV Mat结构的图片 旋转顺时针90度 180度 270度 逆时针90度
- 有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度。 给定一个NxN的矩阵,和矩阵的阶数N,请返回旋转
- JAVA代码—算法基础:将N*N的矩阵顺时针旋转90度输出元素
- 算法:数组顺时针、逆时针90度旋转
- android解决坚屏拍照和保存图片旋转90度的问题,并兼容4.0
- 图像旋转算法-向左旋转90度
- C#图片处理之:旋转图片90度的整数倍
- 矩阵顺时针旋转90度
- 关于android中调用系统拍照,返回图片是旋转90度..
- php旋转图片90度的方法
- php旋转图片90度的方法
- C#图片处理之:旋转图片90度的整数倍
- opencv 图片旋转90度
- 图片正(逆)旋转90度java小程序