Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Problems using ImageIO  (Read 2321 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Devvie




Java games rock!


« Posted 2004-02-24 09:17:36 »

very sorry for the dummy post before !!
you should never have bottles in the radius of your keyboard ...

my first try to substitue the old 1.1 method for image-work is not too succesfull.
im very ashamed to have such problems so early  Embarrassed

following code written in an applet:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
                URL u = getClass().getResource("avatar.jpg");

            BufferedImage img=null;
           
                 try
            {
                  img = ImageIO.read(u);
            }
            catch(IOException e)
            {
                  System.out.println("error");
            }

            g.drawImage(img, 0, 0, this);
}


with that code i get a securityException, java is unable to create a temporary file ... (?)


but before i have more problems after getting this one solved i need further tips:
i want to replace the old code which was written to cut a big image into pieces (only for referencing the new pieces, not for writing on disk)
i used a conglomerate of ImageProducer, FilteredImageSource and CropImageFilter.

what is the best way of doing it in javax.imagIO ?
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #1 - Posted 2004-02-24 11:19:34 »

Sometimes ImageIO makes temp files (so it can be sure it is able to rewind the input stream or do other performance enhancements, I think).

You can turn that feature off.  Call ImageIO.setUseCache(false)

Offline Serethos

Junior Devvie




Java games rock!


« Reply #2 - Posted 2004-02-25 10:06:44 »

ok, problem is gone.

but another question:
i just noticed the BufferedImage.getSubImage() methode (perfekt for cutting my images into pieces).
normally i cut the parts and store them as "stand-alone" images in a collection object as tiles.
but the method offers to do the cut-operation just in time so that a animation object hold only the big image and returns a tile on demand. the only reason i see for not using this technique could be that getSubImage is much too slow (?!)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2004-02-25 10:27:05 »

getSubImage is handy, but performance-wise it sucks badly. The returned image isn't a new, stand alone image but shares the same data as the original. So what you think is a nice cache-friendly 32x32 image is actually a section of a monster 256x256 image (for example).

For best speed I found:
- load single big image (much faster disk reading).
- Chop up into lots of sub images (via getSubImage)
- Copy sub images into their own new images (faster drawing, better image caching).

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2004-02-25 11:24:01 »

Chop up and copy can be done at the same time... you can specify a clipping region with drawImage Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
chars = new BufferedImage[52];
for(int i=0;i<52;i++)
{
      chars[i] = gc.createCompatibleImage(6,5,Transparency.BITMASK);
      tg = (Graphics2D)chars[i].getGraphics();
      tg.setComposite(AlphaComposite.Src);
      tg.drawImage(cmImg,
            0,0,
            6,5,
            i*6,0,
            i*6+6,5,
            null);
      tg.dispose();
}


After that I have all of these chars in a seperate BufferedImage Smiley

Click to Play

(these cute chars are hand pixelated)

弾幕 ☆ @mahonnaiseblog
Offline Serethos

Junior Devvie




Java games rock!


« Reply #5 - Posted 2004-02-26 07:37:15 »

@Orangy Tang

if i get you right, it is ok to do it this way :

1  
2  
3  
4  
5  
BufferedImage img = ImageIO.read(getClass().getResource("animation.png"));
BufferedImage allTiles[] = new BufferedImage[50];
allTiles[i] = img.getSubimage(i*cellWidth, 0, cellWidth, cellHeight);
(...)
img = null
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #6 - Posted 2004-02-26 08:31:45 »

No, you're making the same mistake. While that apparenly gives you lots of small images they're actually just referencing the original big image (and nulling the reference to the original doesn't make any difference). What you need to do after that is create your 'proper' animation images as new buffered images, then copy each image in your tiles array into its own new image.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Serethos

Junior Devvie




Java games rock!


« Reply #7 - Posted 2004-02-26 09:29:06 »

ugh, it was ment to be so. but what you write isnt everytime what youre thinking about ...

but now i get the clue, thx
Offline peter_ljung

Junior Newbie




Java games rock!


« Reply #8 - Posted 2005-03-15 07:06:28 »

If you don't have the option to create tiles on beforehand and wan't to draw a small part of a large image.

I have tried two variants
1. getSubImage() ... which then is drawn
2. setClip() in combination with AffineTransform and the draw the whole image.

Which is preferred?

Thanks!

/ Peter
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2005-03-15 07:14:10 »

It depends on how often the section of the image your want to draw is going to change.

If its the same section every time (i.e. a tile) then producing a seperate image in some way (subImage() is one option) is preferred.

If you're constantly changing the section of the image your want to draw you might find sectioning the drawing more efficent (i.e. setClip() method).

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline peter_ljung

Junior Newbie




Java games rock!


« Reply #10 - Posted 2005-03-15 07:31:30 »

Thanks for your quick reply ...

The large image is really a part of my world that is painted whenever the world has changed or the view area has moved. The world consists of quad tree of image objects.
I use a scrollbuffer to keep the current viewarea and its surroundings. The scroll buffer is only updated when view area has exceeded the scrollbuffer area.

The process is as follows:
1. Paint needed part of the world to large image
2. Paint part of world (in 4 parts) to scroll buffer
3. Paint shown area of the scroll buffer to canvas

Possibly I shouldn't use the temporary file at all and instead get the four parts from the world directly. The downside is the quadtree must be searched 4 times instead on one.
Offline Mark_J

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-03-16 19:18:30 »

Just reading this and its got me wondering,

im just sorting out a scroll bg that uses tiles (32x32) and with seeing this about cutting the tiles into thier own buffers, does that mean that by creating individual buffers for each tile, they blit faster than how I currently do it via:

calculate the tile position in the tile image, then in my g.drawImage i set the destinations x,y width height and also the source width height etc etc.

and that then gets blitted onto the backbuffer screen.

heres the code :
(tilex & tiley are the offsets into the image containing the tiles)
(twidth & theight are the tile sizes (32x32 in this instance)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
      int tilex = map[world_X_offset+tx][ty+world_Y_offset]%20;
      int tiley = map[world_X_offset+tx][ty+world_Y_offset]/20;

        int dx = tx*twidth-(int)scroll_X_offset;
        int dy = ty*theight-(int)scroll_Y_offset;
        int dw = tx*twidth+32-(int)scroll_X_offset;
        int dh = ty*theight+32-(int)scroll_Y_offset;
        int sx =tilex*32;
        int sy = tiley*32;
        int sw = sx+32;
        int sh = sy+32;
        g.drawImage(title,dx,dy,dw,dh,sx,sy,sw,sh,null);


it is a long winded way to do it, so was wondering how to streamline it, and it looks like the cut tiles into individual buffers sounds like a good plan. just thought id ask about the difference and what ppl thought.

TIA

total noob, so forgive my complete and utter dumb questions!
Offline peter_ljung

Junior Newbie




Java games rock!


« Reply #12 - Posted 2005-03-17 16:18:26 »

I suppose that it would be preferred to divide the tiles in separate buffered images if it is possible. The drawImage() function you use supports scaling of the image and depending on how effective this implementation is the performance may be different. Question is if implementation checks if scaling is performed or not and in this case exclude any transform operation.

Ordinary drawImage(img, x,y, obs) cannot be implemented in too many different ways. Later on I will try all methods and do some profiling but I'm not there yet.

An overview of different graphics drawing operations and its performance would be great but I haven't found any.
Offline Malohkan

Senior Devvie




while (true) System.out.println("WOO!!!!");


« Reply #13 - Posted 2005-03-17 18:36:55 »

I believe Mark_J's method is the fastest of all.  It's also good in consideration that it would also be best for use in OpenGL.  I'm pretty sure the Graphics2D implementations check for scaling first and if there is none, simply draw the appropriate region.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
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.

rwatson462 (34 views)
2014-12-15 09:26:44

Mr.CodeIt (25 views)
2014-12-14 19:50:38

BurntPizza (52 views)
2014-12-09 22:41:13

BurntPizza (85 views)
2014-12-08 04:46:31

JscottyBieshaar (47 views)
2014-12-05 12:39:02

SHC (61 views)
2014-12-03 16:27:13

CopyableCougar4 (63 views)
2014-11-29 21:32:03

toopeicgaming1999 (125 views)
2014-11-26 15:22:04

toopeicgaming1999 (115 views)
2014-11-26 15:20:36

toopeicgaming1999 (33 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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