private
    
    
     void
    
    
     AnalysisImage
    
    
     (
    
    
     string
    
    path
    
     ,
    
    
     string
    
    targetPath
    
     )
    
    
     FileStream
    
    fs
    
     =
    
    
     new
    
    
     FileStream
    
    
     (
    
    path
    
     ,
    
    FileMode
    
     .
    
    Open
    
     )
    
    
     ;
    
    
    
     BinaryReader
    
    br
    
     =
    
    
     new
    
    
     BinaryReader
    
    
     (
    
    fs
    
     )
    
    
     ;
    
    
    
     byte
    
    
     [
    
    
     ]
    
    imageBuffer
    
     =
    
    
     new
    
    
     byte
    
    
     [
    
    br
    
     .
    
    BaseStream
    
     .
    
    Length
    
     ]
    
    
     ;
    
    
    br
    
     .
    
    
     Read
    
    
     (
    
    imageBuffer
    
     ,
    
    
     0
    
    
     ,
    
    Convert
    
     .
    
    
     ToInt32
    
    
     (
    
    br
    
     .
    
    BaseStream
    
     .
    
    Length
    
     )
    
    
     )
    
    
     ;
    
    
    
     string
    
    textString
    
     =
    
    System
    
     .
    
    Convert
    
     .
    
    
     ToBase64String
    
    
     (
    
    imageBuffer
    
     )
    
    
     ;
    
    
    fs
    
     .
    
    
     Close
    
    
     (
    
    
     )
    
    
     ;
    
    
    br
    
     .
    
    
     Close
    
    
     (
    
    
     )
    
    
     ;
    
    
    System
    
     .
    
    IO
    
     .
    
    File
    
     .
    
    
     WriteAllBytes
    
    
     (
    
    targetPath
    
     ,
    
    imageBuffer
    
     )
    
    
     ;
    
    
    AssetDatabase
    
     .
    
    
     Refresh
    
    
     (
    
    
     )
    
    
     ;
    
    
    
    
     
      
       将
       
        PNG
       
       图片转精灵
       
        Sprite
       
       图片
      
     
    
    
     
      
       
        使用场景:将外部Png图片,显示在软件中。设置个头像、设置背景之类的自定义设置功能
       
      
      
     
     
      
     
    
    using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class ChinarSpriteToPng : MonoBehaviour
    
    
    
    public void OnClick_PngToSprite()
        
        GameObject.Find("PNG To Sprite/Sprite").GetComponent<Image>().sprite = PngToSprite(Application.streamingAssetsPath + "/PngToSprite/Chinar1.jpg", 300, 300);
    
    
    
    
    
    
    
    private Sprite PngToSprite(string fullPath, int x, int y)
        using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read)) 
            fs.Seek(0, SeekOrigin.Begin);            
            byte[] bytes = new byte[fs.Length];      
            fs.Read(bytes, 0, (int) fs.Length);      
            Texture2D texture = new Texture2D(x, y); 
            texture.LoadImage(bytes);
            return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one / 2);
 
 将  Unity 中的精灵图片 Sprite 转为 Png 并 IO 保存下来
 
使用场景:将软件中的图片保存。将指定的UI 精灵图保存到本地
 
 
using System.IO;
using UnityEngine;
public class ChinarSpriteToPng : MonoBehaviour
    
    
    
    public void OnClick_SpriteToPng()
        Sprite     sprite = Resources.Load<Sprite>("WeChat1");                                                             
        byte[]     bt     = sprite.texture.EncodeToPNG();                                                                  
        FileStream fs     = new FileStream(Application.streamingAssetsPath + "/SpriteToPng/WeChat1.png", FileMode.Create); 
        using (fs)
            fs.Write(bt, 0, bt.Length); 
            fs.Flush();
 
 项目文件为 unitypackage 文件包:
 
下载导入 Unity 即可使用
 
 
 
 
 
     拥有自己的服务器,无需再找攻略
 Chinar  提供一站式《零》基础教程
使有限时间 具备无限可能!  
Chinar 知你所想,予你所求!(  Chinar Blog  )
 
				public static byte[] AuthGetFileData(string fileUrl)
    FileStream fs = new FileStream(fileUrl, FileMode.Open, FileAccess.Read);
    byte[] buffur = new byte[fs.Length];
    fs.Read(buffur, 0, buffur.Length);
    fs.Close();
				图集拆分后可以将子图单独保存成
png图片,使用如下代码,
var 
sprites = Resources.LoadAll<
Sprite>("main");
Debug.Log("拆分的
图片如下:");
var path = "D:/Splite/";
if (!Directory.Exists(path))
    Directory.CreateDirectory(path);
int counter = 0;
foreach (var 
sprite in 
sprites)
				
Css Sprite,有时也称为雪碧图、精灵图,是每一个前端开都会遇到的问题,也是常见的小图片加载优化手段。相信各位同学都清楚其原理,具体就不赘述了。
之前一直有动机利用html5实现一个合成雪碧图的工具,方便小项目的快速开发,减少一些诸如开photoshop、fireworks等工具来合图的机械劳动,最近终于抽出时间将构思实现。
 在线使用:http://alloyteam.github.com/gopng
 使用介绍:http://www.alloyteam.com/?p=1050
Go!Png介绍:
目前实现的功能如下:
 支持图片文件拖拽
 支持生成png图片与css文件
 支持两种自动排列的模式
 放大镜功能
 磁力吸附对齐功能
 工作状态导出功能,可以方便导出文件,在下一次操作通过拖放改文件来恢复工作状态(包括图片数据跟参数设置)
 支持Mac(Chrome) :)
                            标签:GoPng
                    
                Unity EasySave3中文图文教程详解-万能数据保存插件多平台支持
                    拔丝辣条: 
                    
                Unity UGUI Layout自动排版组件用法介绍
                    「已注销」: 
                    
                Unity官方支持中文版啦!!!附教程——无需破解!
                    Breeze_i: