0

so.. I've made a Java Class (in Eclipse) that converts an PNG image to a 5 times bigger image with sprite replacements for the colors in the original image..

I try to export it to a runnable jar, but it will not allow it.

The error message: Description Resource Path Location Type Build path specifies execution environment JavaSE-1.6. There are no JREs installed in the workspace that are strictly compatible with this environment. ImageConverter Build path JRE System Library Problem

here is the code:

package Converter;

import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class changeImage {
    public static void main(String args[]) throws IOException {
        //Load map
        File file = new File("src/Converter/rcs/BaseMap.png");
        BufferedImage image = ImageIO.read(file);
        File other = new File("src/Converter/rcs/BlankMap.png");
        BufferedImage Theimage = ImageIO.read(other);


        //Read sprites
        File sprites = new File("src/Converter/rcs/Sprites.png");
        BufferedImage spriteImg = ImageIO.read(sprites);
        int r = spriteImg.getWidth() /5;
        System.out.println(r);
        int MySprites[][][] = new int[100][5][5];
        for (int k = 0; k < r; k++) {
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 5; j++) {
                    MySprites[k][j][i] = spriteImg.getRGB((k*5)+j, i);
                }
            }
        }


        //Converter
        for (int i = 0; i < image.getHeight(); i++) {
            for (int j = 0; j < image.getWidth(); j++) {
                int color = image.getRGB(j, i);
                System.out.println(color);
                //-16777216     =(0)
                //-12629812     =(1)
                //-8421505      =(2)
                //-14503604     =(3)
                //-1237980      = 4)
                //-16735512     =(5)
                //-3584         =(6)
                //-14066        =(7)
                //-4856291      =(8)
                //-32985        =(9)
                //-3947581      =(10)
                //-4621737      =(11)
                //-7864299      =(12)
                //-20791        =(13)
                //-3620889      =(14)
                //-6075996      =(15)
                //-9399618      =(16)

              //if black convert to sprite 0
                if(color == -16777216) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[0][b][a]);
                        }
                    }
                }

                //if red convert to sprite 1
                if(color == -12629812) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[1][b][a]);
                        }
                    }
                }
              //if black convert to sprite 2
                if(color == -8421505) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[2][b][a]);
                        }
                    }
                }

                //if red convert to sprite 3
                if(color == -14503604) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[3][b][a]);
                        }
                    }
                }
              //if black convert to sprite 4
                if(color == -1237980) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[4][b][a]);
                        }
                    }
                }

                //if red convert to sprite 5
                if(color == -16735512) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[5][b][a]);
                        }
                    }
                }
              //if black convert to sprite 6
                if(color == -3584) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[6][b][a]);
                        }
                    }
                }

                //if red convert to sprite 7
                if(color == -14066 ) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[7][b][a]);
                        }
                    }
                }
              //if black convert to sprite 8
                if(color == -4856291 ) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[8][b][a]);
                        }
                    }
                }

                //if red convert to sprite 9
                if(color == -32985) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[9][b][a]);
                        }
                    }
                }
              //if black convert to sprite 10
                if(color == -3947581) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[10][b][a]);
                        }
                    }
                }

                //if red convert to sprite 11
                if(color == -4621737) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[11][b][a]);
                        }
                    }
                }
              //if black convert to sprite 12
                if(color == -7864299) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[12][b][a]);
                        }
                    }
                }

                //if red convert to sprite 13
                if(color == -20791 ) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[13][b][a]);
                        }
                    }
                }
              //if black convert to sprite 14
                if(color == -3620889) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a, MySprites[14][b][a]);
                        }
                    }
                }

                //if red convert to sprite 15
                if(color == -6075996 ) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a,     MySprites[15][b][a]);
                        }
                    }
                }
              //if black convert to sprite 16
                if(color == -9399618) {
                    for(int a = 0; a <5; a++) {
                        for(int b = 0; b <5; b++) {
                            Theimage.setRGB((j*5)+b, (i*5)+a,     MySprites[16][b][a]);
                        }
                    }
                }



            }
        }
        try {
            // retrieve image
            File outputfile = new File("src/Converter/rcs/saved.png");
            ImageIO.write(Theimage, "png", outputfile);
        } catch (IOException e) {

        }
    }
}

Any suggestions?

4

1 回答 1

1

也许您为您的项目设置了错误的 JRE 系统库。您需要删除错误的,并添加正确的。

您需要转到项目属性、Java 构建路径、库选项卡,删除现有的 JRE 系统库并添加您的。看看这里的答案。

请注意,如果您使用的是 Maven,问题可能是由于 pom.xml 中的设置而发生的,因此您需要更改它,这样您就不必每次都编辑项目属性。

于 2013-10-16T17:49:09.910 回答