Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Java 2D / Graphics.copyArea bug?
|
on: 2012-01-17 12:36:11
|
Hello, I have a problem when using copyArea to scroll an image with a negative dx value (that is, scroll an image to the left) with an opaque picture format. Here is a simple test I performed in a JFrame: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public class TestFrame extends javax.swing.JFrame {
private BufferedImage buffer = null; public TestFrame() { try { BufferedImage img = ImageIO.read(new File("/home/lauwenmark/tmp/test.jpg")); this.buffer = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = this.buffer.createGraphics(); g2d.drawImage(img, 0, 0, this); g2d.dispose(); } catch (IOException ex) { ex.printStackTrace(); this.buffer = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB); } }
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D)g; super.paint(g); g2d.drawImage(this.buffer, 0, 0, this); } |
And I scroll using this: 1 2 3 4
| Graphics2D g2d = buffer.createGraphics(); g2d.copyArea(64, 0, this.buffer.getWidth()-64, this.buffer.getHeight(), -64, 0); g2d.dispose(); this.repaint(); |
When this.buffer is of TYPE_INT_ARGB, it works as expected. However, when using TYPE_INT_RGB, it doesn't and ends up corrupting the display like this:  Uploaded with ImageShack.usWhere am I doing it wrong? Or is it a bug in copyArea?
|
|
|
|
|
3
|
Java Game APIs & Engines / Java 2D / Re: Colour->Grayscale conversion failure using ColorConvertOp on Mustang
|
on: 2006-08-19 00:22:07
|
My apologizes, I obviously copied the wrong stack trace - you'll find the correct one below. I used the following piece of code: 1 2 3 4 5 6 7 8 9 10 11 12
| (...) BufferedImageOp operation = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); try { System.out.println("BEFORE:"+my_icon); my_disabled_icon = operation.filter(my_icon, null); } catch (Exception e) { e.printStackTrace(); System.out.println("AFTER :"+my_icon); } |
And got the following results: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| my_icon BEFORE:BufferedImage@5aaa4bf8: type = 0 ColorModel: #pixelBits = 16 numComponents = 2 color space = java.awt.color.ICC_ColorSpace@6261b548 transparency = 3 has alpha = true isAlphaPre = false ByteInterleavedRaster: width = 32 height = 32 #numDataElements 2 dataOff[0] = 0
java.lang.NullPointerException at java.awt.image.ComponentColorModel.getDataElements(ComponentColorModel.java:1538) at sun.awt.image.PixelConverter.rgbToPixel(PixelConverter.java:39) at sun.java2d.loops.SurfaceType.pixelFor(SurfaceType.java:400) at sun.java2d.SurfaceData.pixelFor(SurfaceData.java:691) at sun.java2d.SunGraphics2D.validateColor(SunGraphics2D.java:1646) at sun.java2d.SunGraphics2D.<init>(SunGraphics2D.java:242) at sun.java2d.SunGraphicsEnvironment.createGraphics(SunGraphicsEnvironment.java:349) at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1137) at java.awt.image.ColorConvertOp.ICCBIFilter(ColorConvertOp.java:317) at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:262)
(... the rest of the stack is the app-specific location of the error, which is the convert() line.)
my_icon AFTER :BufferedImage@5aaa4bf8: type = 0 ColorModel: #pixelBits = 16 numComponents = 2 color space = java.awt.color.ICC_ColorSpace@6261b548 transparency = 3 has alpha = true isAlphaPre = false ByteInterleavedRaster: width = 32 height = 32 #numDataElements 2 dataOff[0] = 0 |
I indeed get no error with a JDK 1.5.0-07. Actually, I didn't seem to get that error with an earlier version of the JDK (I think the last one I used before b94 was b85). Although there is multithreading in the application, there is no modification possible in that block, as there's only one thread that access it, so it isn't an issue.
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 2D / Colour->Grayscale conversion failure using ColorConvertOp on Mustang
|
on: 2006-08-17 11:36:24
|
Hi, Here is what I want to do: I have a color BufferedImage, and I want to convert it to a grayscale one. The original image is stored as a PNG. I came up with the following code fragment (I use the Sixlegs PNG library to load PNG files, as it appears that ImageIO sometimes fails to load some of them): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| BufferedImageOp operation = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); BufferedImage my_icon; BufferedImage my_disabled_icon;
(...)
try { my_icon = new PngImage().read(new File("duke.png")); my_disabled_icon = operation.filter(my_icon, null); } catch (IOException e) { (...) } |
my_icon indeed contains a valid Image - I verified this by blitting the content of my_icon on screen. OTOH, my_disabled_icon triggers a NullPointerException with Java Mustang (build 94) at the operation.filter() line. A typical Exception trace starts with: 1 2
| java.lang.NullPointerException at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:238) |
I am puzzled by this - did I forget anything, or is that a bug I inadvertantly jumped on ? Also, maybe there's another, better way to generate a grayscale image from a coloured one ?
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Resizing problem with Java 1.5, OpenGL and bufferStrategy
|
on: 2006-08-11 17:29:28
|
Hi, I'm developping an application that uses bufferStrategy to display its content using double-buffering in a window. But there is indeed a problem I cannot solve when using an 1.5 JVM with the opengl pipeline. A short example to explain where the problem is. I first took the sample code given in: http://www.java-gaming.org/forums/index.php?topic=117.0Then, I changed the content of render() so that it displays a 40x40 image of Duke: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| private void render() { if( !bufferStrategy.contentsLost() ) { Graphics2D g = (Graphics2D)(bufferStrategy.getDrawGraphics()); g.setColor( Color.white ); g.fillRect( 0, 0, mainFrame.getWidth(), mainFrame.getHeight() );
g.translate(0,27); g.scale((float)mainFrame.getWidth()/40.0,(float)(mainFrame.getHeight()-27)/40.0); g.fillRect( 0, 0, mainFrame.getWidth(), mainFrame.getHeight() ); g.drawImage(img,0,0,null); i++; if( i > 400 ) Running = false;
bufferStrategy.show(); g.dispose(); } } |
I make a vertical translation of 27 because that's the thickness of my window title - so my Duke isn't partially masked by it. Then I rescale so that the picture will take the whole window space, and finally, I fill the background with white, and finish by drawing the picture. Under Mustang, that works perfectly:  Same under 1.5 with the "software" rendering pipeline. But now, with the opengl pipeline, that's what I get when resizing the window:  What exactly am I doing wrong ? Is there a solution to this ?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|