java - How to rotate a bitmap with AffineTransform -
I am trying to create a simple program that displays bitmap zombie images and then using AffineTransform and Thread Revolves around I followed the example to fulfill it, but whenever I run a program, Zombie Bitmap revolves and stops once. Apart from this, for some reasons when I painted the zombie bitmap, the image comes in part with the Wi-axis from the screen.
So my questions are: why bitmap is not rotating and why the bitmap is off screen.
The code is as follows:
Import java.awt. *; // import the graphics class java.awt.geom. *; Import java.net *; // import navigation javax.swing. *; // JFrame import java.util *; // Toolkit implements the public class BitMapZombies2 JFrame tool Runnable {Personal Image zombieOneRight; Thread zombiran; Public stationary zero main (string [] args) {new bitmap jombs 2 (); } Public BitMapZombies2 () {Super ("Bit map zombies .. stops for your life !!!"); SetSize (800600); SetVisible (true); SetDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Toolkit Zkit = Toolkit.getDefaultToolkit (); Zombie Lift = Zkit.getImage (getURL ("_ images / _production_images / zombie_1_left_75h.png")); ZombieOneRight = Zkit.getImage (getURL ("_ images / _production_images / zombie_1_right_75h.png")); Zombiron = new thread (this); ZombieRun.start (); } AffineTransform zombieIdentity = New AffineTransform (); Private URL getURL (string filename) {URL url = null; Try {url = this.getClass (). GetResource (filename); } Hold (exception e) {} return url; } Public Zero Color (Graphics Z) {Graphics2D z2d = (Graphics2D) z; AffineTransform ZombiePowered = New AffineTransform (); Z2d.setColor (Color.BLACK); Z2d.fillRect (0,0, 800, 600); ZombiePowered.setTransform (zombieIdentity); ZombiePowered.rotate (2,37.5,37.5); Z2d.drawImage (zombieOneRight, ZombiePowered, this); } Public Zero Run () {Thread zT = Thread curentThread (); While (zT == zombieRun) {try {thread.sleep (500); } Grip (Interrupted e) e.printStackTrace (); } Color (); }}} Appreciate any help that I can get on it.
Comment of your code:
AffineTransform ZombiePowered = New AffineTransform ( ); // Create an ID; Change ZombiePowered.setTransform (zombieIdentity); // Set this as a copy of an ID Change ZombiePowered.rotate (2, 37.5, 37.5); // Context Annotation with Rotation with the Id z2d.drawImage (zombieOneRight, ZombiePowered, this); // Apply rotation so always your rotating 2rads your image. If you do this assignment at the end of the paint method:
zombieidentity = zombie power; The next time you paint the picture, it will rotate 2 rand more. Regarding the issues with the situation, take a look at Javadok's rotation:
It changes with a change that turns coordinates around an anchor point. This operation is equivalent to translating the coordinates so that the anchor points are on the original (S1), then moving them about the new parent (S2), and finally translate so that the intermediate root is in the coordinates of the original anchor point Can be restored (S3).
This operation is equivalent to the following sequence of calls:
Translation (Encorex, Encryary); // S3: Last Translation Rotate (Theta); // S2: Anchor revolves around translations (-norcores, - tequin); // S1: Translate anchor to the original Hope it helps.
Comments
Post a Comment