-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
1.2.2
-
x86
-
windows_nt
Name: wl91122 Date: 07/19/99
I had a couple of different bugs. One was that the application of a clipping
region that intersected the image would cause the image to shift into
the visible portion of the clip. I'm guessing that this one was the
inability to use a negative transform, i.e. one that would translate
the origin of the image to, for example, <-6,-10>. But it's been
awhile.
My image is a png, I don't know if this happens with a non-png.
Here is a test program. Note that I'd expect that negative
translation should work, but it doesn't.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.renderable.ParameterBlock;
import java.awt.image.RenderedImage;
import java.awt.geom.AffineTransform;
import java.util.Vector;
import javax.media.jai.*;
public class JAItester extends JFrame
{
public static JAItester theApp;
double scale;
int srcoffset;
int dstoffset;
JLabel scalel, offsetsrcl, offsetdestl;
RenderedImage image;
JLabel canvas;
public JAItester(String filename)
{
JPanel panel;
JButton button;
JScrollBar scalesb, offsetsrc, offsetdest;
JPanel p;
JLabel l;
JPanel outputpanel;
ParameterBlock pb = new ParameterBlock().add(filename);
image = (RenderedImage) JAI.create("fileload", pb, null);
try {
// Steel L&F
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception exc) {
System.err.println("Error loading L&F: " + exc);
exc.printStackTrace();
}
getContentPane().setLayout(new BorderLayout());
setSize(640,480);
panel = new JPanel();
panel.setLayout(new BorderLayout());
getContentPane().add(panel, BorderLayout.CENTER);
p = new JPanel();
p.setLayout(new FlowLayout());
l = new JLabel("Scale factor: ");
p.add(l);
scalesb = new JScrollBar(JScrollBar.HORIZONTAL, 10, 1, 1, 50);
scalesb.setSize(200, 20);
p.add(scalesb);
l = new JLabel("Source offset x,y: ");
p.add(l);
offsetsrc = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 50);
offsetsrc.setSize(200, 20);
p.add(offsetsrc);
l = new JLabel("Destination offset x,y: ");
p.add(l);
offsetdest = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 50);
offsetdest.setSize(200, 20);
p.add(offsetdest);
panel.add(p, BorderLayout.NORTH);
p = new JPanel();
p.setLayout(new FlowLayout());
scalel = new JLabel("");
offsetsrcl = new JLabel("");
offsetdestl = new JLabel("");
p.add(scalel);
p.add(offsetsrcl);
p.add(offsetdestl);
panel.add(p, BorderLayout.SOUTH);
canvas = new JLabel("Image Display Area");
canvas.setSize(150, 150);
panel.add(canvas, BorderLayout.CENTER);
scalesb.addAdjustmentListener( new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
scale = (double) e.getValue() / 10.0;
Update();
}
});
offsetsrc.addAdjustmentListener( new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
srcoffset = e.getValue();
Update();
}
});
offsetdest.addAdjustmentListener( new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
dstoffset = e.getValue();
Update();
}
});
}
public void Update() {
Graphics2D cg = (Graphics2D) canvas.getGraphics();
AffineTransform xform;
// Put new values up
scalel.setText("Scale factor: " + Double.toString(scale));
offsetsrcl.setText("Source offset: " + Integer.toString(srcoffset));
offsetdestl.setText("Dest offset: " + Integer.toString(dstoffset));
// Clear it
cg.setBackground(Color.blue);
cg.clearRect(0, 0, 200, 200);
// Do it
xform = new AffineTransform();
xform.translate((double) dstoffset, (double) dstoffset);
xform.scale(scale, scale);
xform.translate((double) -srcoffset, (double) -srcoffset);
cg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
cg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
cg.drawRenderedImage(image, xform);
}
/**
* The main entry point for the application.
*
* @param args Array of parameters passed to the application
* via the command line.
*/
public static void main(String args[])
{
if (args.length < 1) {
System.err.println("JAItester imagefile");
System.exit(-1);
}
theApp = new JAItester(args[0]);
theApp.setVisible(true);
}
}
(Review ID: 53730)
======================================================================