打包工具的使用请参考
奋斗小土豆丶的博文 http://blog.sina.com.cn/s/blog_940dd50a0101cvp1.html
反打包工具
1。这个网上已经有了
public static void main(String[] args) {
toPNG("D:/libgdx-0.9.8/tools/test-me!/inputpng/canyonbunny-ui.pack",
"D:/libgdx-0.9.8/tools/test-me!/inputpng/canyonbunny-ui.png",
"D:/libgdx-0.9.8/tools/test-me!/outputpng");
}
public static void toPNG(String pathTxt, String pathPNG, String OUT) {
ArrayList<String> name = new ArrayList<String>();
ArrayList<String> xy = new ArrayList<String>();
ArrayList<String> size = new ArrayList<String>();
Boolean isfirst = true ;
int num = 5;
try {
String encoding = "GBK";
File file = new File(pathTxt);
if (file.isFile() && file.exists()) { // 判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
int lineNum = 0, lineNum2 = 0;
while ((lineTxt = bufferedReader.readLine()) != null) {
if(isfirst){
if(lineTxt.trim().equals("")){
num = 6 ;
}else{
num = 5;
}
isfirst = false ;
}
lineNum++;
if (lineNum2 > 0)
lineNum2++;
if (lineNum == num)
lineNum2 = 1;
if (lineNum % 7 == num)
name.add(lineTxt);
if (lineNum2 % 7 == 3)
xy.add(lineTxt);
if (lineNum2 % 7 == 4)
size.add(lineTxt);
}
read.close();
} else {
System.out.println("找不到指定的文件");
}
System.out.println(xy);
System.out.println(size);
BufferedImage image = (BufferedImage) ImageIO
.read(new File(pathPNG));
for (int i = 0; i < name.size(); i++) {
String p1 = name.get(i), p2 = xy.get(i), p3 = size.get(i);
int x = 0, y = 0, w = 0, h = 0, flag = 0;
for (int j = 0; j < p2.length(); j++) {
if (p2.charAt(j) <= '9' && p2.charAt(j) >= '0') {
if (flag == 0) {
x = x * 10 + p2.charAt(j) - '0';
} else {
y = y * 10 + p2.charAt(j) - '0';
}
}
if (p2.charAt(j) == ',')
flag = 1;
}
flag = 0;
for (int j = 0; j < p3.length(); j++) {
if (p3.charAt(j) <= '9' && p3.charAt(j) >= '0') {
if (flag == 0)
w = w * 10 + p3.charAt(j) - '0';
else
h = h * 10 + p3.charAt(j) - '0';
}
if (p3.charAt(j) == ',')
flag = 1;
}
File f = new File(OUT);
if (!f.exists())
f.mkdirs();
ImageIO.write(image.getSubimage(x, y, w, h), "png",
new FileOutputStream(OUT + "/" + p1 + ".png"));
System.out.println(p1 + ".png生成成功");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
}
2.用libgdx的包写的
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "CanyonBunny";
cfg.useGL20 = false;
cfg.width = 1;
cfg.height = 1;
new LwjglApplication(new RestoreTexturePackerLibGdx(), cfg).exit();
}
}
public class RestoreTexturePackerLibGdx extends Game {
TextureAtlas atlas;
ArrayList<String> name = new ArrayList<String>();
ArrayList<String> xy = new ArrayList<String>();
ArrayList<String> size = new ArrayList<String>();
@Override
public void create() {
String out = "D:/libgdx-0.9.8/tools/test-me!/outputpng_test";
atlas = new TextureAtlas(Gdx.files.internal("data/canyonbunny.pack"));
Array<AtlasRegion> array = atlas.getRegions();
for(int i=0;i<array.size;i++){
AtlasRegion a = atlas.getRegions().get(i);
name.add(a.name);
xy.add("xy: "+a.getRegionX()+", "+a.getRegionY());
size.add("size: "+a.getRegionWidth()+", "+a.getRegionHeight());
}
BufferedImage image;
try {
image = (BufferedImage) ImageIO
.read(Gdx.files.internal("data/canyonbunny.png").read());
for (int i = 0; i < name.size(); i++) {
String p1 = name.get(i), p2 = xy.get(i), p3 = size.get(i);
int x = 0, y = 0, w = 0, h = 0, flag = 0;
for (int j = 0; j < p2.length(); j++) {
if (p2.charAt(j) <= '9' && p2.charAt(j) >= '0') {
if (flag == 0) {
x = x * 10 + p2.charAt(j) - '0';
} else {
y = y * 10 + p2.charAt(j) - '0';
}
}
if (p2.charAt(j) == ',')
flag = 1;
}
flag = 0;
for (int j = 0; j < p3.length(); j++) {
if (p3.charAt(j) <= '9' && p3.charAt(j) >= '0') {
if (flag == 0)
w = w * 10 + p3.charAt(j) - '0';
else
h = h * 10 + p3.charAt(j) - '0';
}
if (p3.charAt(j) == ',')
flag = 1;
}
File f = new File(out);
if (!f.exists())
f.mkdirs();
ImageIO.write(image.getSubimage(x, y, w, h), "png",
new FileOutputStream(out + "/" + p1 + ".png"));
System.out.println(p1 + ".png生成成功");
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
附上Learning Libgdx Game Development这本书的所有图片素材