-
Rotating a PlanarImage in JAI
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).
Also,the rotated image is not getting stored in the specified location .
Is there any problem with the way I use PlanarImage class of JAI ?
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);
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);
}
}
}
Similar Threads
-
By PoojaPatel in forum C++
Replies: 1
Last Post: 02-15-2005, 06:08 AM
-
Replies: 0
Last Post: 04-15-2002, 01:31 PM
-
Replies: 0
Last Post: 04-15-2002, 01:27 PM
-
By dom in forum Architecture and Design
Replies: 0
Last Post: 04-06-2002, 01:36 AM
-
Replies: 0
Last Post: 04-06-2002, 01:35 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks