Image rotation. Flip. To zoom in and

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;


        public void run(){

                for(int i=0;;i++){
                        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;

        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.setTitle (" Picture of the rotate flipping.  . Zoom in and out  ");
                jf.setLocationRelativeTo (null);
                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++){
                        Thread.sleep (1000);
                        }catch(InterruptedException ie){}


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;

        public void run(){


                                flag = true;
                                flag = false;

                                Thread.sleep (100);

                        }catch(InterruptedException ie){
                                ie.printStackTrace ();


        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); 

分类:Java 时间:2010-05-28 人气:262
blog comments powered by Disqus


  • Java to determine whether the string contains characters 2010-11-19

    Java to determine whether the string contains characters import java.util.regex.Matcher; import java.util.regex.Pattern; public class IfHanZi { public static void main(String[] args) { // Method a : String s1 = " I am a Chinese "; String s2 = &q

  • Java is the Chinese character string replacement 2010-06-26

    public static int getLength (String str) ( str = str.replaceAll ("[^ x00-xff] *", "**"); System.out.print (str); return str.length (); ) public static void main (String [] args) throws UnsupportedEncodingException ( String str = "

  • java to get the main information page of the three: html to tree (rpm) 2010-12-04

    1. Required Documents param.txt: storing the path need to extract information page TestPage: need to extract the information stored pages Out.txt: page content output 2. Test program package test; import*; import Source.*; // Extract the mai

  • public static void main (String args []) parameters 2010-05-15

    String args [] is the main function of main parameters, namely array of strings. Using eclipse in the editing, right-click to run the Java files in the Run As option, select Run Configurations. Main class in the Project and complete the project, resp

  • Why public static void main (String args []){} 2010-11-06

    main () is a Java program entry, program execution is the beginning of this entry. Class is a class member, main () method must be public members. So that it can be called in the execution environment. main () method does not produce the object can b

  • How the eclipse of the main the String [] args parameter passed, and then export it 2010-12-26

    How the eclipse of the main the String [] args parameter passed, and then export it? In the Run menu to find Open Run dialog opens Select Java Application in the program need to run Select the Arguments Tab Enter the parameters in the Programe Argume

  • 浅析C#中的Main(String[] args)参数输入问题 2014-07-20

    本篇文章主要是对C#中的Main(String[] args)参数输入问题进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 指定相关的测试代码 首先,写一个用于测试的关于Main(String[] args)参数输入有关的代码类,如下: using System; public class Hello { public static void Main(String[] args) { switch (args[0]) { case "老板": Console.Write

  • java data type conversion Integer String Long Float Double Date 2010-07-24

    1 How to convert integer string String int? A. There are two ways: 1). Int i = Integer.parseInt ([String]); or i = Integer.parseInt ([String], [int radix]); 2). Int i = Integer.valueOf (my_str). IntValue (); Note: The string converted to Double, Floa

  • Java, how to convert a string into a date format 2010-10-05

    Java, convert string into date format is commonly used as a function of Among many projects, will use the drops, is also useful prior to, but I am a bad memory So, decided to write this blog, frequently used functions to facilitate the later can be u

  • java source code of the String 2010-12-07

    1.String Source Squadron String class description: The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant; their values cannot be chang

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.582 (s). 12 q(s)