dcsimg
rotating an image using JAI
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Preeti_Gopal
Posted On:   Monday, February 28, 2011 06:27 AM

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 ? Also, the rotated image is not getting stored in any file in the specified location. There are no compilation errors in the code. Please help. import java.applet.*; import java.awt.event.*; import java.awt.*; import j   More>>

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 ?
Also, the rotated image is not getting stored in any file in the specified location.

There are no compilation errors in the code.

Please help.

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

}

}

}

   <<Less
About | Sitemap | Contact