关于生成.png的问题。求高手指点

fanglei1233 2012-01-11 05:57:50
先上代码:

import System.IO;

@MenuItem ("Assets/Save Font Texture")

static function SaveFontTexture () {
var tex = Selection.activeObject as Texture2D;
if (tex == null) {
EditorUtility.DisplayDialog("No texture selected", "lease select a texture", "Cancel");
return;
}
if (tex.format != TextureFormat.Alpha8) {
EditorUtility.DisplayDialog("Wrong format", "Texture must be in uncompressed Alpha8 format", "Cancel");
return;
}

// Convert Alpha8 texture to ARGB32 texture so it can be saved as a PNG
var texPixels = tex.GetPixels();
var tex2 = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
tex2.SetPixels(texPixels);

// Save texture
var texBytes = tex2.EncodeToPNG();
var fileName = EditorUtility.SaveFilePanel("Save font texture", "", "font Texture", "png");
if (fileName.Length > 0) {
var f : FileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
var b : BinaryWriter = new BinaryWriter(f);
for (var i = 0; i < texBytes.Length; i++) b.Write(texBytes);
b.Close();
}

DestroyImmediate(tex2);
}


这个脚本是用在UNITY3D中的,作用是通过TTF字库生成一个.png格式的texture,问题来了,这段代码是把TTF字库中所有字符生成到一个PNG图片中,这样导致图片过大,各位大侠看能不能帮忙优化一下,只生成需要的文字的图片。
...全文
90 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellNo 2012-01-12
  • 打赏
  • 举报
回复
我也看不懂!~
KeenWon 2012-01-11
  • 打赏
  • 举报
回复
看不懂啊

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧