Unity3d Ngui Atlas cut into pictures

Source: Internet
Author: User

Unity3d Ngui Atlas cut into pictures

Sometimes use Ngui to do the atlas, then the original image is not necessary to put into the unity3d, seriously affect the speed of unity3d. But suddenly the right side wants to get the picture out. Of course Ngui is provided with a single picture in the gallery save, but if the picture is too many, compare time, so with Python wrote a cut the image of the tool code as follows:

Python environment: 2.7 test pass, need to rely on image Library
Ngui Version: 3.7

#coding: Utf-8#unity Atlas cut into Png#author:wiker yong#date:2015-07-08import osimport sysimport argparseimport Imagedef Middle (str= ", left=", right= "): # Print Str.index (Right,str.index (left) +1) return Str[str.index (left) +len (left): St R.find (Right,str.find (left) +1)]parser = Argparse. Argumentparser (description= ' Unity Atlas cut to PNGs ') parser.add_argument ("-F", dest= ' file ', help= ' cut prefab,no ext Name ') parser.add_argument ("-P", dest= ' path ', help= ' Output path ') args = Parser.parse_args () out_path= "if args.path! = None and not Os.path.exists (Args.path): Os.makedirs (args.path) Out_path = args.pathif Args.file = = NONE:PARSER.P Rint_help () sys.exit (0) Prefab_path = args.filepngprefab_file = open (prefab_path+ '. Prefab ') Pngname= ' x=0y=0w=0h=    0while 1:line= prefab_file.readline () if not line:break;        If Line.startswith ('-Name: '): Pngname=middle (line, '-Name: ', ' \ r \ n ') if Line.startswith (' x: '): X=int (Middle (line, ' x: ', ' \ r \ n ')) if LINE.STARTSWith (' y: '): Y=int (Middle (line, ' Y: ', ' \ r \ n ')) if Line.startswith (' width: '): W=int (Middle (line , ' width: ', ' \ r \ n ')) if Line.startswith (' Height: '): H=int (Middle (line, ' Height: ', ' \ r \ n ')) PRI NT Pngname,x,y,w,h img = Image.open (prefab_path+ '. png ') region = (x,y,w+x,h+y) cropimg=img.crop (Regio N) cropimg.save (out_path+ '/' +pngname+ '. png ')

Follow up the whole Unity Anti-compilation, restore to the picture, please pay attention!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unity3d Ngui Atlas cut into pictures

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.