Screem
|
 |
«
Posted
2012-03-29 01:12:08 » |
|
A few questions have been bothering me for a while and I didn't find any good answers on Google, so here I go... - Does scaling an image using graphics.drawImage(Image image, x, y, w, h, ImageObserver io) unmanage it?
- Does using getSubImage(), getRGB(), and setRGB() unmanage an image?
- If scaling an image using the graphics.drawImage() method shown above unmanages an image, are there any alternatives?
- If using any of the three methods in the second bullet unmanage an image, are there any alternatives?
- Is it better to scale each tile to the size you need it in the code, or have all the tiles pre-scaled?
I'm trying to get the best out of my game, and in order to do so, I want to know the best way to render images. Thanks for any help!  Also, sorry if this is in the wrong section. I didn't know if to put this here or in Java 2D, and I ended up posting it here. 
|
|
|
|
Jimmt
|
 |
«
Reply #1 - Posted
2012-03-29 01:24:25 » |
|
This is not very noobie, put it in java2d.
|
|
|
|
theagentd
|
 |
«
Reply #2 - Posted
2012-03-29 01:55:40 » |
|
Scaling or rotating is veeeery slow to do unmanaged, so it would make absolutely no sense at all if graphics.drawImage(Image image, x, y, w, h, ImageObserver io) unmanaged the image, would it?  I'd say that's your safest bet. I'm 99% sure that getRGB and setRGB unmanages the image. For hardware acceleration to work the data has to be stored on the GPU. If you access pixel data in any way it has to be stored on the CPU --> can't be accelerated. Other than that, I don't know much about Java2D... ._.
|
Myomyomyo.
|
|
|
Games published by our own members! Check 'em out!
|
|
Regenuluz
|
 |
«
Reply #3 - Posted
2012-03-29 04:39:24 » |
|
I'm playing around with tiles right now and I tried going from pre-drawn tiles to just rotating them, and that actually cost me around 60fps, so that's rather expensive. So I'll be doing pre-drawn tiles. And my guess is it would be the same with scaling? But I suppose it all depends on how many images you're scaling/rotating each time you render the screen. If it's only 1-2 then it might not be so bad. As for getSubimage(), I don't know if that makes it unmanaged, but if you cache the subimages, so that you don't have to get it from the tileset each time you try to render the screen, then it shouldn't be so bad. (That's what I'm doing anyways)
|
|
|
|
ra4king
|
 |
«
Reply #4 - Posted
2012-03-29 05:09:08 » |
|
getSubimage, image scaling, and getRGB do not unmanage the image. Only when you modify the pixel data will the image become unmanaged.
|
|
|
|
Riven
|
 |
«
Reply #5 - Posted
2012-03-29 10:29:57 » |
|
getSubimage, image scaling, and getRGB do not unmanage the image. Only when you modify the pixel data will the image become unmanaged.
... and when you call BufImg.getRaster(), it will immediately be unmanaged, whether you modify pixels or not.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
nsigma
|
 |
«
Reply #6 - Posted
2012-03-29 10:46:53 » |
|
getSubimage, image scaling, and getRGB do not unmanage the image. Only when you modify the pixel data will the image become unmanaged.
... and when you call BufImg.getRaster(), it will immediately be unmanaged, whether you modify pixels or not. Pretty sure that's not true. Calling getDataBuffer() used to unmanage the image AFAIK, and now with the addition of sun.java2d.StateTrackable only actually getting your hands on the data array should unmanage.
|
Praxis LIVE - hybrid visual IDE for (live) creative coding
|
|
|
Riven
|
 |
«
Reply #7 - Posted
2012-03-29 10:50:19 » |
|
Pretty sure that's not true. Calling getDataBuffer() used to unmanage the image AFAIK, and now with the addition of sun.java2d.StateTrackable only actually getting your hands on the data array should unmanage.
I confused the two, thanks for correcting me.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Screem
|
 |
«
Reply #8 - Posted
2012-03-29 11:30:45 » |
|
If using setRGB() or modifying the pixel data unmanges an image, then is there ANY way to modify pixel data without unmanaging the image? Currently I use setRGB() to change the color of text, and I sort of can't get rid of text color. I'm able to render 1000 text tiles at ~ 40 - 45 FPS, with only using setRGB() on the tiles once and saving the modified images into a HashMap and reading them from there from then on.
|
|
|
|
ra4king
|
 |
«
Reply #9 - Posted
2012-03-29 14:04:37 » |
|
Set the pixels on a temporary BufferedImage, draw that BufferedImage to a managed BufferedImage, and then draw that BufferedImage to the screen.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
sproingie
|
 |
«
Reply #10 - Posted
2012-03-29 16:36:33 » |
|
getSubImage won't make the original image unmanaged, but the image that's returned is unmanaged. Good thing to know if you're trying to do a sprite sheet.
|
|
|
|
nsigma
|
 |
«
Reply #11 - Posted
2012-03-29 18:42:33 » |
|
Set the pixels on a temporary BufferedImage, draw that BufferedImage to a managed BufferedImage, and then draw that BufferedImage to the screen.
Setting pixels shouldn't cause an image to become unmanaged so the temporary image should be overkill.
|
Praxis LIVE - hybrid visual IDE for (live) creative coding
|
|
|
ra4king
|
 |
«
Reply #12 - Posted
2012-03-29 21:12:23 » |
|
Yes, setting pixels does make the image unmanaged.
|
|
|
|
Screem
|
 |
«
Reply #13 - Posted
2012-03-29 21:57:54 » |
|
Thanks for all the help, everyone! Just one last question, to @ra4king, how do I draw a BufferedImage to a BufferedImage? I'm not exactly sure what you mean by this. 
|
|
|
|
nsigma
|
 |
«
Reply #14 - Posted
2012-03-29 22:11:07 » |
|
Yes, setting pixels does make the image unmanaged.
It depends how you do it. getRaster().setDataElements() should be fine, and I think setRGB() should be these days. There's also a system property that allows raster stealing so that images are never unmanaged.
|
Praxis LIVE - hybrid visual IDE for (live) creative coding
|
|
|
ra4king
|
 |
«
Reply #15 - Posted
2012-03-29 22:50:22 » |
|
how do I draw a BufferedImage to a BufferedImage? I'm not exactly sure what you mean by this.  1 2 3 4 5 6
| BufferedImage src = .... BufferedImage dest = ....
Graphics2D g = dest.createGraphics(); g.drawImage(src,0,0,null); g.dispose(); |
|
|
|
|
Screem
|
 |
«
Reply #16 - Posted
2012-03-30 00:30:41 » |
|
how do I draw a BufferedImage to a BufferedImage? I'm not exactly sure what you mean by this.  1 2 3 4 5 6
| BufferedImage src = .... BufferedImage dest = ....
Graphics2D g = dest.createGraphics(); g.drawImage(src,0,0,null); g.dispose(); |
Thanks sooo much! Really appreciate it! 
|
|
|
|
|