Image rotation. Flip. To zoom in and

sponsored links
Image rotation, flip, zoom in and out

Actually rewrite paint (Graphics g) method

drawImage (Image img, int x, int y, int width, int height, ImageObserver observer)

Scaling picture only need to change the type of parameter can be a few int

Class Graphics2D method rotate (double theta, double x, double y) can be used to rotate a picture

The first parameter: rotation angle in radians as the unit value

Second, the three parameters: rotation, respectively X and Y coordinates of the origin

import java.awt.*;
import javax.swing.*;

public class RotatePicture extends JLabel implements Runnable{
        
        static Image img = new ImageIcon("D:/Backup/ My documents/water in  .jpg").getImage ();
        static double[] rad = {0,Math.PI/2,Math.PI,-Math.PI/2};
        double theta = 0; 

        public void paintComponent(Graphics g){
                Graphics2D g2d = (Graphics2D)g;
                g2d.rotate(theta,250,250);
                g2d.drawImage(img,100,100,300,300,null);
                
        }
        
        public void run(){
                                                        
                for(int i=0;;i++){
                         try{
                        Thread.sleep (10);
                        }catch(InterruptedException ie){}
                        
                        // You can sign to change the direction of rotation  
                        rotate(Math.toRadians(i));// Radian values  
                }
        }
        
        public void rotate(double d){
                theta = d;
                repaint();
        }
        
        public static void main(String[] args){
                JFrame jf = new JFrame();
                jf.setSize (500,530);   
                RotatePicture rp = new RotatePicture(); 
                RotatePicture rp1 = new RotatePicture();
                MyPicture mp = new MyPicture(img,jf);
                JTabbedPane tabbedPane = new JTabbedPane();
                tabbedPane.add(" Any angle rotation  ", rp);
                tabbedPane.add("90 Degree flip  ", rp1);
                tabbedPane.add(" Zoom in and out  ", mp);
                jf.add(tabbedPane);
                jf.setTitle (" Picture of the rotate flipping.  . Zoom in and out  ");
                jf.setLocationRelativeTo (null);
                jf.setVisible(true);
                jf.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
                Thread t1 = new Thread(rp);
                t1.start ();            
                Thread t2 = new Thread(mp);
                t2.start ();
                for(int i=0;i<4;i++){
                         try{
                        Thread.sleep (1000);
                        }catch(InterruptedException ie){}
                        rp1.rotate(rad[i]);
                        if(i==3)i=-1;
                }               
        }
                        
}

class MyPicture extends Canvas implements Runnable{     
        Image img ;
        int w;
        int h;
        int width; 
        int height;
        int rate;
        boolean flag;
        
        public MyPicture(Image image,Container c){
                img = image;
                w = 50;
                h = 50;                                                                         
                width = c.getWidth();
                height = c.getHeight()-50;
                rate = 10;
                flag = false;
                System.out.println(width+","+height);
        }
        
        public void run(){
                
                while(true){
                        
                        if(w<=0||h<=0)
                                flag = true;
                        if(w>=width||h>=height)
                                flag = false;
                        
                        try{
                                Thread.sleep (100);
                                
                        }catch(InterruptedException ie){
                                ie.printStackTrace ();
                        }

                        if(flag){
                                w+=10;
                                h+=10;
                        }
                        if(!flag){
                                w-=10;
                                h-=10;                                  
                        }
                        repaint();      
                }
        }
        
        public void paint(Graphics g){

                // The upper-left corner of the coordinate set a picture               
                int x = (width-w)/2;
                int y = (height-h)/2;
                g.drawImage(img, x, y, w, h,null); 
                 
        }
}
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Image rotation. Flip. To zoom in and

  • log4j easy application in java

    JAVA development, frequently used the log output, in a so-called most of the software company will have its own set of configuration style, re-read the configuration file to initialize property of the log, it will be good, but sometimes may not need to fu

  • jboss ejb3 Message Driven Bean

    Super Medium ejb hate. . . . . . . . . . . . . . . . . . . ================================================ To configure a Message Driven Bean in a different application server parameters are not the same. Currently only passed the test jboss. Message Dri

  • JDBC example of a long time do not have JDBC forgot

    A back-up here to stay. The first: The second:

  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • First Hibernate Example

    Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries