Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Problem with splitting BufferedImage  (Read 2555 times)
0 Members and 1 Guest are viewing this topic.
Offline VIrtueeL
« Posted 2015-08-14 03:28:29 »

so here is where the problem is

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  
   public void init(int worldSize, BufferedImage map){
      this.worldSize = worldSize;
      this.map = map;
     

      //createChunks
      int chunkW = map.getWidth() / worldSize;
      int chunkH = map.getHeight() / worldSize;
     
        int count = 0;
     
      BufferedImage imgs[] = new BufferedImage[chunkW*chunkH];
     
      for (int x = 0; x < worldSize; x++) {  
            for (int y = 0; y < worldSize; y++) {
            imgs[count] = new BufferedImage(chunkW, chunkH, map.getType());

              Chunk chunke = new Chunk(x*8*32, y*8*32,imgs[count++]);  
               chunkList.add(chunke);
           
            System.out.println(count+" IMG: "+map.getData()+" RGB: "+map.getRGB(x, y));
            }  
        }

      for(Chunk chunks : chunkList){
         chunks.initChunk();
      }
     
   }


what i'am trying to do is get 8 pixels out off the BF and create a chunk out off it then jump another 8 pixels and make a new chunk but they are all black when they go into the array why?

tell me if you need more info this is the chunk init

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
   public void initChunk(){
     
     
      if(currChunkImg != null){
         for(int w = 0; w < chunkSize; w++){
            for(int h = 0; h < chunkSize; h++){
                int rgb = currChunkImg.getRGB(w, h);
               
                switch(rgb & 0x000000){
                   case 0x000000:
                      blocks.add(new Block(pos.xpos + w*32,pos.ypos + h*32));
                  break;
//                   case 0xFFFFFF:
//                      blocks.add(new Block(pos.xpos + w*32,pos.ypos + h*32));
//                  break;
                }
               
               
            }
                 
         }
      }
     
   }


and when i render with
1  
g.drawImage(currChunkImg,(int)pos.xpos, (int)pos.ypos,64,64,null);

in the chunk class
it shows a black image

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline ra4king

JGO Kernel


Medals: 506
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2015-08-14 05:44:30 »

I don't see where you are drawing to the BufferedImage. Of course the internal array is going to be all 0's when you first create it, so all black.

Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #2 - Posted 2015-08-14 06:53:26 »

Depending on whether they actually need to be separate instances, you may get utility out of getSubImage().

E.g:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
/** Split parent into numX by numY spritesheet */
public static BufferedImage[][] split(BufferedImage parent, int numX, int numY) {
    BufferedImage[][] tiles = new BufferedImage[numX][numY];
    int tileW = parent.getWidth() / numX;
    int tileH = parent.getHeight() / numY;

    for (int x = 0; x < numX; x++)
        for (int y = 0; y < numY; y++)
            tiles[x][y] = parent.getSubImage(x * tileW, y * tileH, tileW, tileH);

    return tiles;
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline VIrtueeL
« Reply #3 - Posted 2015-08-14 10:38:32 »

i want to get the data out off the map image and split in to smaller temp images

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline jonjava
« Reply #4 - Posted 2015-08-14 11:35:37 »

Then do what BurntPizza suggests. I used a similar method for a thing I scribbled some two years ago (also implemented it in NodeJS since I was getting into that at the time) which cuts a sprite sheet into smaller icon-sized images - which then serves a random of these icons on each request through http.



source for the nodejs implementation

Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (21 views)
2017-11-21 16:21:00

xxMrPHDxx (14 views)
2017-11-21 16:14:31

xxMrPHDxx (16 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (150 views)
2017-09-26 18:23:31

cybrmynd (258 views)
2017-08-02 12:28:51

cybrmynd (249 views)
2017-08-02 12:19:43

cybrmynd (247 views)
2017-08-02 12:18:09

Sralse (260 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!