Libgdx: Restores a PNG Image packaged by texturepacker into a single

Source: Internet
Author: User
Tags libgdx

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



Libgdx: Restores a PNG Image packaged by texturepacker into a single

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.