[classlib][awt][image] PixelGrabber does not work
-------------------------------------------------
Key: HARMONY-4802
URL: https://issues.apache.org/jira/browse/HARMONY-4802
Project: Harmony
Issue Type: Bug
Components: Classlib
Environment: Win32
Reporter: Chunrong Lai
Below is the reproducer which throws ArrayIndexOutOfBoundsException. Actuaaly it is because
that the PixelGrabber does not work.
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class DrawImageTest extends JFrame {
public Image image;
public static void main(String[] args){
DrawImageTest aTest = new DrawImageTest();
if(args.length <1) {
System.out.println("Please input a valid image name");
System.exit(0);
}
aTest.setSize(800, 600);
aTest.readImage(args[0]);
aTest.show();
}
public DrawImageTest(){}
public void readImage(String imageName){
if(image == null) {
image = Toolkit.getDefaultToolkit().getImage(imageName);
MediaTracker imageTracker = new MediaTracker(new JPanel());
imageTracker.addImage(image, 0);
try{
imageTracker.waitForID(0);
}catch(InterruptedException e){}
if(image == null) System.out.println("we get an image of null");
else {
int width = image.getWidth(this);
int height = image.getHeight(this);
System.out.println("we get an image of width " + width + " height " + height);
int size = width * height;
int[] pixels = new int[size];
PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, width, height, pixels,
0, width);
try {
pixelgrabber.grabPixels();
}
catch (InterruptedException _ex) {_ex.printStackTrace();}
MemoryImageSource memoryimagesource = new MemoryImageSource(width, height,
new DirectColorModel(24, 0xff0000, 0x00ff00, 0x0000ff), pixels, 0, width);
try {
memoryimagesource.setAnimated(true);
memoryimagesource.setFullBufferUpdates(true);
image = createImage(memoryimagesource);
memoryimagesource.newPixels();
} catch (NoSuchMethodError _ex) {}
}
}
}
public void paint(Graphics g){
super.paint(g);
g.drawImage(image, 0, 0, null);
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
|