图片旋转

简介: 图片旋转

R7-17 图片旋转 (30 分)


二维图片由一个个像素点组成,目前灰度图像使用一个0-255之间的整数表示某个像素点的像素值。编程完成图片旋转控制程序。


本题目要求读入2个整数m和n(<=20),作为图片的长宽尺寸。输入1个整数r,作为旋转角度(只能输入90 180 -90中的一个,90表示图形向左旋转90度,-90表示图形向右旋转90度)。然后按照行列输入图片像素值,


输入格式:


第一行:2个整数m和n(<=20)


第二行:2个整数r(只能是90 180 -90中的一个,否则提示:angle data error


第三行以后:输入m行n列的整数数据,必须在0-255之间,否则提示:matrix data error


以上输入的都是整数,若有非整数的数据输入,统一提示:data type error


输出格式:


按要求旋转后的图片矩阵数据


输入样例:


在这里给出一组输入。例如:


3 4
90
1 2 3 4
5 6 7 8
9 10 11 12


输出样例:


在这里给出相应的输出。例如:


1. 4 8 12
2. 3 7 11
3. 2 6 10
4. 1 5 9


R7-17 图片旋转 (30 分)
二维图片由一个个像素点组成,目前灰度图像使用一个0-255之间的整数表示某个像素点的像素值。编程完成图片旋转控制程序。
本题目要求读入2个整数m和n(<=20),作为图片的长宽尺寸。输入1个整数r,作为旋转角度(只能输入90 180 -90中的一个,90表示图形向左旋转90度,-90表示图形向右旋转90度)。然后按照行列输入图片像素值,
输入格式:
第一行:2个整数m和n(<=20)
第二行:2个整数r(只能是90 180 -90中的一个,否则提示:angle data error
第三行以后:输入m行n列的整数数据,必须在0-255之间,否则提示:matrix data error
以上输入的都是整数,若有非整数的数据输入,统一提示:data type error
输出格式:
按要求旋转后的图片矩阵数据
输入样例:
在这里给出一组输入。例如:
3 4
90
1 2 3 4
5 6 7 8
9 10 11 12
3 4
180
1 2 3 4
5 6 7 8
9 10 11 12
输出样例:
在这里给出相应的输出。例如:
4 8 12
3 7 11
2 6 10
1 5 9
import java.util.Scanner;
public class J_17 {
  public static void main(String[] args) {
    // TODO 自动生成的方法存根
    @SuppressWarnings("unused")
    int a = 0, b = 0, c = 0, f = 0;
    @SuppressWarnings("unused")
    int i = 0, j = 0;
    @SuppressWarnings("unused")
    int d[][] = new int[21][21];
    @SuppressWarnings({ "unused", "resource" })
    Scanner sc = new Scanner(System.in);
    if (sc.hasNextInt()) {
      a = sc.nextInt();
    } else {
      f = 1;
    }
    if (sc.hasNextInt()) {
      b = sc.nextInt();
    } else {
      f = 1;
    }
    if (sc.hasNextInt()) {
      c = sc.nextInt();
      if (c != 90 && c != -90 && c != 180) {
        System.out.println("angle data error");
      } else {
        for (i = 0; i < a; i++) {
          for (j = 0; j < b; j++) {
            if (sc.hasNextInt()) {
              d[i][j] = sc.nextInt();
            } else {
              f = 1;
            }
            if (!(d[i][j] >= 0 && d[i][j] <= 255)) {
              System.out.println("matrix data error");
            }
          }
        }
        if (f == 1) {
          System.out.println("data type error");
        } else if (c == 90) {
          for (i = b - 1; i >= 0; i--) {
            for (j = 0; j < a; j++) {
              if (j == 0)
                System.out.print(d[j][i]);
              else
                System.out.print(" " + d[j][i]);
            }
            System.out.print("\n");
          }
        } else if (c == -90) {
          for (i = 0; i < b; i++) {
            for (j = a - 1; j >= 0; j--) {
              if (j == a - 1)
                System.out.print(d[j][i]);
              else
                System.out.print(" " + d[j][i]);
            }
            System.out.print("\n");
          }
        } else {
          for (i = a - 1; i >= 0; i--) {
            for (j = b - 1; j >= 0; j--) {
              if (j == b - 1)
                System.out.print(d[i][j]);
              else
                System.out.print(" " + d[i][j]);
            }
            System.out.print("\n");
          }
        }
      }
    } else {
      f = 1;
      System.out.println("angle data error");
    }
  }
}
目录
相关文章
裁剪图片
裁剪图片
63 0
裁剪图片
|
Java
PNG图片透明背景变黑
Java中PNG图片透明背景变黑
559 0
PNG图片透明背景变黑
|
Python
图片旋转 90、180、270
图片旋转 90、180、270
156 0
百叶窗图片切换
在线演示 本地下载
957 0
3d旋转动画焦点图
在线演示 本地下载
663 0
|
C# 小程序
给图片加上阴影效果
原文:给图片加上阴影效果 今天写一个小程序有一个给图片加上阴影的需求,记得WPF的Effect中就有阴影特效,就打算用它了。代码如下:     using (var imageStreamSource = File.
1185 0
u3d无锯齿遮罩shader-可用于ugui
图片.png 图片.png // 遮罩shader Shader "Custom/CircleMask" { Properties{ _MainTex("MainTex", 2D) = "white" ...
1707 0