Libgdx: Restores a PNG Image packaged by Texturepacker to a single image,
Do you find that Texturepacker is used to package and compress resource files. I lost the original file, but I had no choice but to add a new small png. This article is a lot of Baidu's methods after the blogger encountered this problem, unfortunately, only the plist format is available, and libgdx is barely available. I did not find one, so I wrote one myself.
Two files are generated in the package.
One is **. txt and the other is **. png (some are not. txt but. pack, as long as the content is the same. You can use NotePad to open it)
Here, the txt record location and other parameter information. png is a large image.
card.pngformat: RGBA8888filter: Linear,Linearrepeat: nonec36 rotate: false xy: 2, 550 size: 63, 86 orig: 63, 86 offset: 0, 0 index: -1btn1 rotate: false xy: 644, 2 size: 156, 57 orig: 156, 57 offset: 0, 0 index: -1c41 rotate: false xy: 392, 550 size: 63, 86 orig: 63, 86 offset: 0, 0 index: -1
The above is the location information file.
The following uses java to restore a large image to a small image based on this file.
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> (); try {String encoding = "GBK "; file file = new File (pathTxt); if (file. isFile () & file. exists () {// determine whether the file exists InputStreamReader read = new InputStreamReader (new FileInputStream (file), encoding );// Considering the encoding format BufferedReader bufferedReader = new BufferedReader (read); String lineTxt = null; int lineNum = 0, lineNum2 = 0; while (lineTxt = bufferedReader. readLine ())! = Null) {lineNum ++; if (lineNum2> 0) lineNum2 ++; if (lineNum = 5) lineNum2 = 1; if (lineNum % 7 = 5) name. add (lineTxt); if (lineNum2% 7 = 3) xy. add (lineTxt); if (lineNum2% 7 = 4) size. add (lineTxt);} read. close ();} else {System. out. println ("the specified file cannot be found");} 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'; elseh = 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 + ": finished") ;}} catch (Exception e) {System. out. println ("An error occurred while reading the file content"); e. printStackTrace ();}}
The original web site reprint must be noted: http://blog.csdn.net/cq361106306/article/details/38036737
Usage. Direct call
toPNG("d:/card.txt","d:/card.png","d:/s");
The first parameter is a text parameter file, not necessarily a txt suffix. Different Software Generation is different, as long as the content opened with notepad is the same as the above txt.
The second parameter is a large image file.
The third parameter is the output. Do not add "/" at the end; the path is automatically created.
The test is successful here. Leave a message if you have any questions.
Make a small advertisement
Please support my landlords APP. Supports single-host, double, and triple online,
It's called a Wi-Fi landlord
Address click open link http://www.wandoujia.com/apps/com.hj.joker