rotating an image - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

rotating an image

newtoappletsnewtoapplets Posts: 1Member
hi all,

In the following code,

I have created 2 buttons- "normal" and "rotated".
When "normal" is clicked, an image is displayed ( as expected),
but when "rotated" is clicked - no image is displayed ( although I have written the code to display the rotated form of the previous normal image).

Is there any problem with the way I use PlanarImage class of JAI .
There are no compilation errors in the code.

Please help.

[code]

import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.renderable.*;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.*;
import javax.media.jai.widget.ScrollingImagePanel;

public class trial1 extends Applet implements ActionListener{

Image img ;
MediaTracker tr;
Graphics g;
int s;
ScrollingImagePanel imagePanel1;

public void init(){

Button b = new Button("normal");
Button c = new Button("rotated");

b.addActionListener(this);
c.addActionListener(this);

add(b);
add(c);

}
public void actionPerformed(ActionEvent e){

Button source = (Button)e.getSource();
if(source.getLabel() == "normal")
{
s=0;
repaint();
}


if(source.getLabel() == "rotated"){
s=1;
repaint();
}

}

public void paint( Graphics g)
{
tr = new MediaTracker(this);
if (s==0)
{

img = getImage(getCodeBase(), "normal.jpg");
tr.addImage(img,1);
g.drawImage(img, 0,0, this);

}
if (s==1)
{

String args="C:/Documents and Settings/Administrator/Desktop/first_applet/trial1/normal.jpg";
PlanarImage im1 = JAI.create("fileload", args);

float angle = (float)Math.toRadians(45);
float centerX = im1.getWidth()/2f;
float centerY = im1.getHeight()/2f;
ParameterBlock pb = new ParameterBlock();

pb.addSource(im1);
pb.add(centerX);
pb.add(centerY);
pb.add(angle);
pb.add(new InterpolationBilinear());
PlanarImage scaledImage = JAI.create("rotate", pb);
JAI.create("filestore",scaledImage,"C:/Documents and Settings/Administrator/Desktop/first_applet/trial1/rotate.jpg","JPG");

ScrollingImagePanel imagePanel1 = new ScrollingImagePanel(scaledImage, 100, 100);
}

}
}
[/code]
Sign In or Register to comment.