本文整理汇总了C#中UnityEngine.Texture2D.GetRawTextureData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.GetRawTextureData方法的具体用法?C# Texture2D.GetRawTextureData怎么用?C# Texture2D.GetRawTextureData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Texture2D
的用法示例。
在下文中一共展示了Texture2D.GetRawTextureData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static void Create(Texture2D texture)
{
var map = texture.GetRawTextureData();
if (texture.name == "hoge")
{
var alpha = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
var j = 0;
var png = new byte[map.Length];
for(var i = 0; i < map.Length; i += 4)
{
png[i] = 0;
png[i+1] = 0;
png[i+2] = 0;
png[i+3] = map[i];
if (j == texture.width)
{
j = -1;
}
j ++;
}
Debug.Log(alpha.width + ", " + alpha.height);
Debug.Log(map.Length + " - " + png.Length);
alpha.LoadRawTextureData(png);
alpha.Apply();
var pngData = alpha.EncodeToPNG();
string filePath = EditorUtility.SaveFilePanel("Save Texture", "", "alphaMap.png", "png");
if (filePath.Length > 0) {
// pngファイル保存.
File.WriteAllBytes(filePath, pngData);
}
}
using (Stream stream = File.OpenWrite("Assets/Resources/AlphaMap/" + texture.name + ".bytes")) {
using (var writer = new BinaryWriter(stream)) {
writer.Write((uint)texture.width);
writer.Write((uint)texture.height);
for (var i = 0; i < map.Length; i += 4 * 8)
{
int j = i + 4, k = i + 8, l = i + 12, m = i + 16, n = i + 20, o = i + 24, p = i + 28;
byte b = (byte)(
128 * Bit(map, p)+
64 * Bit(map, o)+
32 * Bit(map, n)+
16 * Bit(map, m)+
8 * Bit(map, l)+
4 * Bit(map, k)+
2 * Bit(map, j)+
1 * Bit(map, i));
writer.Write(b);
}
}
}
}
示例2: GetBitmapDataFromFile
public vectorx.ColorStorage GetBitmapDataFromFile(string file)
{
Debug.Log ("Loading bitmap: " + file);
var asset = Resources.Load (file) as TextAsset;
var texture = new Texture2D (2, 2);
texture.LoadImage (asset.bytes);
var bytes = texture.GetRawTextureData ();
var stream = new System.IO.MemoryStream(bytes);
var data = types.Data.fromMemoryStream (stream, bytes.Length);
return new vectorx.ColorStorage (texture.width, texture.height, data);
}