Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 3014 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: 508
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: 486
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  
 
 

 
hadezbladez (292 views)
2018-11-16 13:46:03

hadezbladez (162 views)
2018-11-16 13:41:33

hadezbladez (293 views)
2018-11-16 13:35:35

hadezbladez (73 views)
2018-11-16 13:32:03

EgonOlsen (2154 views)
2018-06-10 19:43:48

EgonOlsen (2181 views)
2018-06-10 19:43:44

EgonOlsen (1368 views)
2018-06-10 19:43:20

DesertCoockie (1985 views)
2018-05-13 18:23:11

nelsongames (1628 views)
2018-04-24 18:15:36

nelsongames (2275 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!