Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Rendering Images; a few questions  (Read 3984 times)
0 Members and 1 Guest are viewing this topic.
Offline 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! Cheesy

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. Huh

Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2012-03-29 01:24:25 »

This is not very noobie, put it in java2d.
Offline 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?  Wink 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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. Tongue

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)
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« 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.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 784
Projects: 4
Exp: 16 years


Hand over your head.


« 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
Offline 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 - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 784
Projects: 4
Exp: 16 years


Hand over your head.


« 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
Offline 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.

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« 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.
Offline 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 - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2012-03-29 21:12:23 »

Yes, setting pixels does make the image unmanaged.

Offline 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. Undecided

Offline 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 - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« 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. Undecided

1  
2  
3  
4  
5  
6  
BufferedImage src = ....
BufferedImage dest = ....

Graphics2D g = dest.createGraphics();
g.drawImage(src,0,0,null);
g.dispose();

Offline 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. Undecided

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! Cheesy

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!