Unity繪制Png圖片


using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class DrawBlockMeshTexture : MonoBehaviour {

    // Use this for initialization
    void Start () {
        int size = 10;
        Texture2D colorTxt = new Texture2D(360* size, 181* size);
        //colorTxt.filterMode = FilterMode.Point;
        for (int i = 0; i != colorTxt.height; i++)
        {
            int lat = i / size;
            // 緯線圈lat上對應的方塊個數
            int blockNumAtLatitude = Mathf.CeilToInt(360 * Mathf.Cos((lat-90) * Mathf.Deg2Rad));
            if (blockNumAtLatitude == 0)
                continue;
            // 每一個小塊對應的像素跨度
            int pixPerBlock = colorTxt.width / blockNumAtLatitude;
            for (int j = 0; j != colorTxt.width; j++)
            {
                if (j % pixPerBlock == 0)
                    colorTxt.SetPixel(j, i, Color.green);
                if (i % size == 0)
                    colorTxt.SetPixel(j, i, Color.red);
            }
        }
        colorTxt.Apply();
        byte[] bytes = colorTxt.EncodeToPNG();
        File.WriteAllBytes(Application.dataPath + "/BlockMeshTexture.png", bytes);
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM