rotate crop & flip image

rotate crop & flip image

Hello frends, I m not getting how to flip image ,crop image & rotate image by 90 degree. can you plz give some ideas...

View Answers

March 1, 2008 at 10:56 AM

Java Example Code - Rotate image by 90 degree

Java Source Code
ImageRotator.html

<HTML>
<HEAD>
</HEAD>
<BODY>
<APPLET ALIGN="CENTER" CODE="ImageRotator.class" WIDTH="800" HEIGHT="500"></APPLET>
</BODY>
</HTML>


ImageRotator.java

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

public class ImageRotator extends JApplet implements ActionListener{
public static final int DEFAULT_SPEED = 50;

private String images[] = {"catfeline.jpg","rose.jpg"};
private JButton button;
private JList list;
private JTextField rotateSpeed;
private JCheckBox checkbox;

public void init(){
getContentPane().setLayout(new BorderLayout());
list = new JList(images);
list.setSelectedIndex(0);
button = new JButton("click me");
button.addActionListener(this);

Panel pane = new Panel(new FlowLayout());
pane.add(button);
Panel panel = new Panel(new FlowLayout());
panel.add(new Label("Enter image rotation speed and direction :"));

rotateSpeed = new JTextField(5);
rotateSpeed.setText(String.valueOf(DEFAULT_SPEED));
checkbox = new JCheckBox("Rotate Clockwise", true);
panel.add(rotateSpeed);
panel.add(checkbox);
getContentPane().add(BorderLayout.NORTH, panel);
getContentPane().add(BorderLayout.CENTER, list);
getContentPane().add(BorderLayout.SOUTH, pane);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource().equals(button)){
String imageName = ((String)(list.getSelectedValue())).trim();
Image image = getImage(getCodeBase(), imageName);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 1);
try{
tracker.waitForAll();
}
catch(InterruptedException e){
System.out.println(e);
}

int speed = DEFAULT_SPEED;
try{
speed = Integer.valueOf(rotateSpeed.getText().trim()).intValue();
}
catch(NumberFormatException ex){
System.out.println(ex);
}
ImageRotatorFrame imageRotator = new ImageRotatorFrame(image, speed, imageName, checkbox.isSelected());
}
}
}

March 1, 2008 at 10:59 AM

now write ImageRotatorFrame.java and run both codes in your computer to rotate image using Java


ImageRotatorFrame.java

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

public class ImageRotatorFrame extends JFrame implements ActionListener{
private ImagePanel imagePanel;
private int rotated;
private Timer rotateTimer;
private JPanel m_imageContainer;

public ImageRotatorFrame(Image image, int speed, String imageName, boolean clockwise){
super("Image Rotator ["+ imageName +"]");
rotated = speed;
if(image == null){
add(new JLabel("Image " + imageName + " not Found"));
}
else{
JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
String mess = "Rotation at:" + rotated + " milli-seconds";
if(clockwise){
mess += "in Clockwise direction";
}
else{
mess += " in Anti-Clockwise direction";
}
topPanel.add(new JLabel(mess));
imagePanel = new ImagePanel(image, clockwise);
getContentPane().add(BorderLayout.NORTH, topPanel);
getContentPane().add(BorderLayout.CENTER, imagePanel);
imagePanel.repaint();
}
setSize(1000, 700);
setVisible(true);
rotateTimer = new Timer(rotated, this);
rotateTimer.start();
}
public void actionPerformed(ActionEvent event){
if(event.getSource().equals(rotateTimer)){
//give call to rotate the image
imagePanel.rotate();
}
}

public class ImagePanel extends JPanel{
public static final int ROTATE_ANGLE = 1;
private Image m_image;
private int RotateAngle;
private int imageWidth, imageHeight;
private AffineTransform transform;
private boolean clockway;

public ImagePanel(Image image, boolean clockwise){
clockway = clockwise;
m_image = image;
imageWidth = m_image.getWidth(this);
imageHeight = m_image.getHeight(this);
if(!clockwise){
RotateAngle = 90 + ROTATE_ANGLE;
}
transform = new AffineTransform();
}
public void paintComponent(Graphics grp){
Rectangle rect = this.getBounds();
Graphics2D graphic = (Graphics2D)grp;
graphic.setColor(Color.pink);
graphic.fillRect(0, 0, getWidth(), getHeight());
transform.setToTranslation((rect.width-imageWidth)/2,(rect.height-imageHeight)/2);
transform.rotate(Math.toRadians(RotateAngle), imageWidth/2, imageHeight/2);
graphic.drawImage(m_image, transform, this);
}

public void rotate(){
if(clockway){
RotateAngle += ROTATE_ANGLE;
RotateAngle %= 90;
}
else{
RotateAngle -= ROTATE_ANGLE;
if(RotateAngle <= 0){
RotateAngle = 90;
}
}
repaint();
}
}
}


Amar ;)









Related Tutorials/Questions & Answers:
rotate crop & flip image - Java Beginners
rotate crop & flip image  Hello frends, I m not getting how to flip image ,crop image & rotate image by 90 degree. can you plz give some ideas...  Java Example Code - Rotate image by 90 degreeJava Source
rotate image in php - PHP
rotate image in php   Function to rotate image in PHP
Advertisements
rotate image with caption
rotate image with caption  How to rotate image with caption
Crop Image Code in Applet
Crop Image Code in Applet  Sir, Can somebody please provide me with code to crop and save an image in applet
Crop Image Code in Applet
Crop Image Code in Applet  Sir, Can somebody please provide me with code to crop and save an image in applet
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
Jmagick crop image
Jmagick crop image  hi, How can I crop the images using Jmagick Thanks.   hi, To crop an image you can use the cropImage() method of MagickImage. Following code explains how an image may cropped ImageInfo ii = new
PHP GD rotate image
<?php $image = 'images.jpg'; $degrees = 180;ADS_TO_REPLACE_1 header('Content-type: image/jpeg') ; $source = imagecreatefromjpeg($image) ; $rotate = imagerotate($source, $degrees, 0) ;ADS_TO_REPLACE_2 imagejpeg
Crop Image
Crop Image       This section shows you how the image get crops. To crop an image.... To crop an image, we have used the CropImageFilter class which is extended
ModuleNotFoundError: No module named 'clean-image-crop-uploader'
ModuleNotFoundError: No module named 'clean-image-crop-uploader'  Hi...: No module named 'clean-image-crop-uploader' How to remove the ModuleNotFoundError: No module named 'clean-image-crop-uploader' error? Thanks  
PHP GD flip image
<?php $image = imagecreatefromjpeg("images.jpg"); $image = flip($image,1,1);ADS_TO_REPLACE_1 header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image);ADS_TO_REPLACE_2 function flip($i
PHP GD crop image
<?php $src = imagecreatefromjpeg('image1.jpg'); $dest = imagecreatetruecolor(80, 40);ADS_TO_REPLACE_1 imagecopy($dest, $src, 0, 0, 20, 13, 80, 40); header('Content-Type: image/jpeg'); imagegif($dest);ADS_TO_REPLACE_2
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
iphone Flip Image
iphone Flip Image In this tutorial will learn how to flip the image, so to do this will use two Image View and a button i.e. bar button for the flip action, whenever we press flip button image should change. For that had to write
Crop Image using plug-in ,JSP and 'Servlet'
Crop Image using plug-in ,JSP and 'Servlet' In this tutorial, we will crop image using jQuery plug-in & servlet. In this example, a image & a button is given.When you press button 'crop image' , it will crop
How to flip image
How to flip image       In this section , you will see how to flip image. To reverse the image, an image is put into the folder where class is specified. The getDefaultToolkit
iphone programming combining move and flip - Java Beginners
iphone programming combining move and flip  Hi, I would like to combine the move image and flip image codes so that i can move and flip different images to show another image
ModuleNotFoundError: No module named 'FLiP'
ModuleNotFoundError: No module named 'FLiP'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'FLiP' How to remove the ModuleNotFoundError: No module named 'FLiP' error
Rotating image in the pdf file
insert a image in a pdf file and rotate it irrespective of the fact whether... Rotating image in the pdf file   ...(). Image.getInstance() gets the image. After that add the content
ModuleNotFoundError: No module named 'resize-and-crop'
ModuleNotFoundError: No module named 'resize-and-crop'  Hi, My... named 'resize-and-crop' How to remove the ModuleNotFoundError: No module named 'resize-and-crop' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'voltorb-flip'
ModuleNotFoundError: No module named 'voltorb-flip'  Hi, My Python... 'voltorb-flip' How to remove the ModuleNotFoundError: No module named 'voltorb-flip' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'cfn-flip'
ModuleNotFoundError: No module named 'cfn-flip'  Hi, My Python...-flip' How to remove the ModuleNotFoundError: No module named 'cfn-flip... to install padas library. You can install cfn-flip python with following
ModuleNotFoundError: No module named 'helga-flip'
ModuleNotFoundError: No module named 'helga-flip'  Hi, My Python... 'helga-flip' How to remove the ModuleNotFoundError: No module named 'helga-flip' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pdfrw-rotate'
ModuleNotFoundError: No module named 'pdfrw-rotate'  Hi, My Python... 'pdfrw-rotate' How to remove the ModuleNotFoundError: No module named 'pdfrw-rotate' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'rotate-backups'
ModuleNotFoundError: No module named 'rotate-backups'  Hi, My... named 'rotate-backups' How to remove the ModuleNotFoundError: No module named 'rotate-backups' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'rotate-backups-s3'
ModuleNotFoundError: No module named 'rotate-backups-s3'  Hi, My... named 'rotate-backups-s3' How to remove the ModuleNotFoundError: No module named 'rotate-backups-s3' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'rotate-proxies'
ModuleNotFoundError: No module named 'rotate-proxies'  Hi, My... named 'rotate-proxies' How to remove the ModuleNotFoundError: No module named 'rotate-proxies' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 's3-backup-rotate'
ModuleNotFoundError: No module named 's3-backup-rotate'  Hi, My... named 's3-backup-rotate' How to remove the ModuleNotFoundError: No module named 's3-backup-rotate' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'aws-rotate'
ModuleNotFoundError: No module named 'aws-rotate'  Hi, My Python... 'aws-rotate' How to remove the ModuleNotFoundError: No module named 'aws-rotate' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'img_rotate'
ModuleNotFoundError: No module named 'img_rotate'  Hi, My Python... 'img_rotate' How to remove the ModuleNotFoundError: No module named 'img_rotate' error? Thanks   Hi, In your python environment you
Spark Rotate Effect in Flex4
Spark Rotate Effect in Flex4: The Rotate effect rotates a component. You can set the starting and ending angle of rotation. The syntax of Rotate effect is following: <s:Rotate id="" angleFrom="" angleTo
ModuleNotFoundError: No module named 'telestream-cloud-flip'
ModuleNotFoundError: No module named 'telestream-cloud-flip'  Hi...: No module named 'telestream-cloud-flip' How to remove the ModuleNotFoundError: No module named 'telestream-cloud-flip' error? Thanks   Hi
ModuleNotFoundError: No module named 'telestream-cloud-flip'
ModuleNotFoundError: No module named 'telestream-cloud-flip'  Hi...: No module named 'telestream-cloud-flip' How to remove the ModuleNotFoundError: No module named 'telestream-cloud-flip' error? Thanks   Hi
ModuleNotFoundError: No module named 'flip-flop-operator'
ModuleNotFoundError: No module named 'flip-flop-operator'  Hi, My... named 'flip-flop-operator' How to remove the ModuleNotFoundError: No module named 'flip-flop-operator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'gym-bit-flip'
ModuleNotFoundError: No module named 'gym-bit-flip'  Hi, My Python... 'gym-bit-flip' How to remove the ModuleNotFoundError: No module named 'gym-bit-flip' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'gym-voltorb-flip'
ModuleNotFoundError: No module named 'gym-voltorb-flip'  Hi, My... named 'gym-voltorb-flip' How to remove the ModuleNotFoundError: No module named 'gym-voltorb-flip' error? Thanks   Hi, In your
MX Rotate Effect in Flex4
MX Rotate Effect in Flex4: The Rotate effect rotates a component. You can set...; 3. originX="0" 4. originY="0" The tag of Rotate effect is <mx:Rotate>. In this example you can see how we can use a Rotate
ModuleNotFoundError: No module named 'rotate-keyboard-layout'
ModuleNotFoundError: No module named 'rotate-keyboard-layout'  Hi...: No module named 'rotate-keyboard-layout' How to remove the ModuleNotFoundError: No module named 'rotate-keyboard-layout' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-rotate-secret-key'
ModuleNotFoundError: No module named 'django-rotate-secret-key'  Hi...: No module named 'django-rotate-secret-key' How to remove the ModuleNotFoundError: No module named 'django-rotate-secret-key' error? Thanks  
ModuleNotFoundError: No module named 'elb-rotate-certs'
ModuleNotFoundError: No module named 'elb-rotate-certs'  Hi, My... named 'elb-rotate-certs' How to remove the ModuleNotFoundError: No module named 'elb-rotate-certs' error? Thanks   Hi, In your
ROTATE THE VOWELS IN A STRING!!! - Java Beginners
ROTATE THE VOWELS IN A STRING!!!  Hi Sir, My Question is to rotate... or lower case, and if it's a vowel or not. Use another function to rotate the vowels. CODING: import jpb.*; public class Rotate_Vowels{ public static
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
image effects - Java Beginners
that will show you image crop effect: import java.sql.*; import java.awt.... JButton("Crop Image"); this.add(crop); crop.addActionListener(new...image effects  hey can u help me in loadin an image file
flex didn't know how to drag and drop video and audio in flip book - Framework
flex didn't know how to drag and drop video and audio in flip book  hello sir in my project in flex flip book it is book which can be flip.our target to add the video audio and photo in this book i am able to add the photo
image scrolling
image scrolling  A brief description of scrolling image
Image Steganography
Image Steganography  SOURCE CODE FOR IMAGE STEGANOGRAPHY

Ads