大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import javax.swing.*;
创新互联网站建设公司,提供网站设计制作、成都做网站,网页设计,建网站,PHP网站建设等专业做网站服务;可快速的进行网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,是专业的做网站团队,希望更多企业前来合作!
import javax.imageio.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.io.*;
/**
* @author Hardneedl
*/
class ImageTransform extends JFrame {
private static final Dimension minSize = new Dimension(900, 800);
private static final Dimension maxSize = new Dimension(900, 800);
private static final Dimension preferredSize = new Dimension(900, 800);
public Dimension getMaximumSize() {return maxSize;}
public Dimension getMinimumSize() {return minSize;}
public Dimension getPreferredSize() {return preferredSize;}
public String getTitle() {return "Frame Title";}
private class Canvas extends JComponent{
private BufferedImage img;
private AffineTransform trans=new AffineTransform();
private void setImage(BufferedImage img){
if(img!=null) this.img = img;
if(isVisible()) paintImmediately(0,0,getWidth(),getHeight());
}
private void setRota(double rota){
trans.setToRotation(rota, (getWidth())1, ( getHeight() )1 );
if(isVisible()) paintImmediately(0,0,getWidth(),getHeight());
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
g.fillRect(0,0,getWidth(),getHeight());
if (img==null)return;
Graphics2D gg= (Graphics2D)g.create();
int iw = img.getWidth(), ih = img.getHeight();
int anchorX = (getWidth()- iw)1, anchorY = (getHeight() - ih)1;
AffineTransform af = gg.getTransform();
af.translate(anchorX, anchorY);
af.concatenate(trans);
gg.drawImage(img,af,this);
gg.dispose();
}
}
private Canvas canvas = new Canvas();
ImageTransform() throws HeadlessException {
init();
doLay();
attachListeners();
}
private void init() {
try {
canvas.setImage(ImageIO.read(new File("1.png")));
canvas.setRota(Math.PI/3);
} catch (IOException e) {
e.printStackTrace();
}
}
private void doLay() {
Container container = getContentPane();
container.add(canvas,BorderLayout.CENTER);
pack();
}
private void attachListeners() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) throws IOException {
new ImageTransform().setVisible(true);
}
}
可以给每一个小方块设置为一个坐标,变为一个三阶行列式,3*3矩阵,转变为二元数组旋转。观察一下左旋:
11 12 13 31 21 11
21 22 23 →→ 32 22 12
31 32 33 33 23 13
坐标变换如下:(1,1)变为(1,3),(1,2)变为(2,3),(1,3)变为(3,3)
(2,1)变为(1,2),(2,2)变为(2,2),(2,3)变为(3,2)
(3,1)变为(1,1),(3,2)变为(2,1),(3,3)变为(3,1)
规律就是(i,j)变为(j,3-i+1):
如果是2*2的方格,就可以变为二阶行列式,也就是2*2的二元数组,这里给出3*3九宫格改变的示意,我的代码如下:
import java.util.Random;
public class T{
public static void main(String[] args){
int[][] a=new int[3][3];
System.out.println("now begin to form a new integer array");
Random r=new Random();
for(int i=0;i3;i++){
for(int j=0;j3;j++){
a[i][j]=r.nextInt(10);
}
}
System.out.println("the array is shown as follows:");
for(int i=0;i3;i++){
for(int j=0;j3;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("左转九十度");
for(int i=0;ia.length;i++){
for(int j=0;ja[i].length;j++){
System.out.print(a[a[i].length-1-j][i]+" ");
}
System.out.println();
}
}
}
由于在double转int时有精度损失,所以转动时会隐约有一条直线。
代码如下:
import java.awt.*;
import javax.swing.*;
public class MyPanel extends JPanel
{
private int r = 150;
private int angle = 0;
public void paintComponent(Graphics g)
{
int x = (int)(r/2*Math.cos(angle/180.0*Math.PI));
int y = -(int)(r/2*Math.sin(angle/180.0*Math.PI));
g.translate(r+10, r+10);
g.setColor(Color.BLACK);
g.fillArc(-r, -r, 2*r, 2*r, angle, -180);
g.setColor(Color.WHITE);
g.fillArc(-r, -r, 2*r, 2*r, angle, 180);
g.fillArc(x-r/2, y-r/2, r, r, angle, -180);
g.setColor(Color.BLACK);
g.fillArc(-x-r/2, -y-r/2, r, r, angle, 180);
g.drawOval(-r, -r, 2*r, 2*r);
g.fillOval(x-10, y-10, 20, 20);
g.setColor(Color.WHITE);
g.fillOval(-x-10, -y-10, 20, 20);
}
public void setAngle(int angle)
{
while(true)
{
if(angle 0)
angle = angle + 360;
if(angle = 360)
angle = angle - 360;
else break;
}
this.angle = angle;
}
public int getAngle()
{
return angle;
}
public static void main(String[] Args)
{
JFrame f = new JFrame();
final MyPanel aPanel = new MyPanel();
f.add(aPanel);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(350, 350);
f.setLocation(300, 200);
Thread aThread = new Thread(){
public void run()
{
while(true)
{
try
{
aPanel.setAngle(aPanel.getAngle() + 1);//加一逆时针转,减一顺时针转
aPanel.repaint();
this.sleep(10);//此处可以调节转动速度
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
};
aThread.start();
}
}
一般是用PDF编辑器旋转的,java好像很高级的样子
打开迅捷PDF编辑器,旋转页面是在文档下面,
找到就可以旋转了,选择逆时针旋转90度,
就可以将PDF文件弄好,最后在文件下面选择保存下。希望可以帮助到楼主。
方法就分享到这里
#includestdio.h
#define N 4
int a[N][N]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
void prt()
{int i,j;
for(i=0;iN;i++)
{
for(j=0;jN;j++)
printf("%4d",a[i][j]);
printf("\n");
}
}
int main()
{int i,j,k,t;
printf("原来的数组:\n");
prt();
for(i=0;i=N/2;i++)
for(j=i;jN-i-1;j++)
{
t=a[i][j];
a[i][j]=a[j][N-1-i];
a[j][N-1-i]=a[N-1-i][N-1-j];
a[N-1-i][N-1-j]=a[N-1-j][i];
a[N-1-j][i]=t;
}
printf("\n顺时针旋转90度后的数组:\n");
prt();
getch();
return 0;
}