java - Lagg fix BufferedImage -


is there image variable buffered image because when launch aplication, reads text document map, laggs lot

my code whith bufferedimage(sorry not english):

for(int = 0; < pole[0].length; i++)     {         for(int j = 0; j < pole.length; j++)         {             if(pole[j][i] == 1)             {                 g.setcolor(color.red);                 try {                     //  g.fillrect(j*40, i*40, 40, 40);                       wall = imageio.read(classloader.getsystemresource("images/wall.gif"));                       g.drawimage(wall, j*40, i*40, null);                 } catch (ioexception ex) {                     joptionpane.showmessagedialog(null, "error: "+ex.getmessage());                 }             }         }     } 

you load image i*j times, when need load once , use same reference each tile.

i.e.

image wall = imageio.read("..."); for(int i=0;i < ...)    for(int j=0;j < ...)       g.drawimage(i*40, j*40, wall); 

you shouldn't things in loops don't belong there, , don't want io in loop. , absolutely don't want load same exact picture every time in loop, since not change between loads.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -