zoukankan      html  css  js  c++  java
  • 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 () {
            
        }
    }
  • 相关阅读:
    break return continue
    爬虫---请求
    pycharm加开头注释
    爬虫---入门
    pip
    XML基础
    英语
    布局
    adobe
    StackOverflow
  • 原文地址:https://www.cnblogs.com/coolbear/p/8867539.html
Copyright © 2011-2022 走看看