Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
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  
  get SubImages in JavaFX  (Read 1418 times)
0 Members and 1 Guest are viewing this topic.
Offline pavul

Senior Devvie


Medals: 4
Exp: 4 years



« Posted 2018-08-25 19:24:23 »

we dont have a specific way to get subimages in JavaFx like we had in Api2D with ImageIO, however i paste this code here so you can transform an image strip into an array of images:

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  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
/*
suppose i have an image strip of 10 frames of 32x32 ( 320x32 ), then i want to separate all frames in individual images
getImage( 10, 32,32,"myStrip.png" );
*/

public static Image[] getImage( int frames, int w, int h,  String pathFile )
        {
           
            Image[] imgs =  new Image[ frames ];
           
            //img that contains all frames
            Image stripImg = new Image( pathFile );
            PixelReader pr =  stripImg.getPixelReader();
            PixelWriter pw = null;
           
            for( int i = 0; i < frames ; i++)
            {
           
                WritableImage wImg = new WritableImage( w, h );
           
                pw = wImg.getPixelWriter();
               
                for( int readY = 0 ; readY < h; readY++ )
                {
               
                    int ww = (w * i);
                    for( int readX = ww; readX < ww + w; readX++ )
                    {
                        //get pixel at X  & Y position
                        Color color = pr.getColor( readX, readY );
                       
                        //set pixel to writableimage through pixel writer
                        pw.setColor(readX - ww, readY, color);
                       
                    }//X
                   
                   
                }//Y
               
               
                //finally new image is stored
                imgs[ i ] = wImg;
            }//
           
           
            stripImg = null;
            pr = null;
            pw = null;
           
        return imgs;
        }//

its better not know why it works, that know why is not working
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (201 views)
2019-09-04 15:33:17

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

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

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

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

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

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

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

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

nelsongames (4306 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

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