本文整理汇总了C#中UnityEngine.Texture2D.LoadRawTextureData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.LoadRawTextureData方法的具体用法?C# Texture2D.LoadRawTextureData怎么用?C# Texture2D.LoadRawTextureData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Texture2D
的用法示例。
在下文中一共展示了Texture2D.LoadRawTextureData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: loadImage
void loadImage(string name)
{
using (BinaryReader b = new BinaryReader(File.Open(name, FileMode.Open,FileAccess.Read,FileShare.Read)))
{
// 2.
// Position and length variables.
int i = 0;
// Use BaseStream.
int length = (int)b.BaseStream.Length;
int w= b.ReadInt32(),h= b.ReadInt32(),format = b.ReadInt32();
texture = new Texture2D (w,h,TextureFormat.RFloat,false);
byte[] data = b.ReadBytes(w*h*format*4);
Debug.Log("Read Ima "+data.Length);
texture.LoadRawTextureData(data);
texture.Apply();
Debug.Log ("Channels "+texture.format);
ccc.callbackLoadImage(w,h);
}
GetComponent<Renderer> ().material.mainTexture = texture;
// GetComponent<Renderer> ().material.SetTexture (2, texture);
Debug.Log ("Channels "+texture.format);
}
示例2: DDSToTexture
public static TextureInfoWrapper DDSToTexture(UrlDir.UrlFile file, TexInfo Texture, bool mipmaps, bool isCompressed, bool hasAlpha)
{
TextureConverter.InitImageBuffer();
FileStream imgStream = new FileStream(Texture.filename, FileMode.Open, FileAccess.Read);
imgStream.Position = 0;
imgStream.Read(imageBuffer, 0, MAX_IMAGE_SIZE);
imgStream.Close();
TextureFormat format = TextureFormat.DXT1;
if(hasAlpha && isCompressed)
{
format = TextureFormat.DXT5;
}
else if(hasAlpha)
{
format = TextureFormat.RGBA32;
}
else if(!isCompressed)
{
format = TextureFormat.RGB24;
}
Texture2D newTex = new Texture2D(Texture.width, Texture.height, format, mipmaps);
newTex.LoadRawTextureData(imageBuffer);
newTex.Apply(false, Texture.makeNotReadable);
newTex.name = Texture.name;
TextureInfoWrapper newTexInfo = new TextureInfoWrapper(file, newTex, Texture.isNormalMap, !Texture.makeNotReadable, isCompressed);
newTexInfo.name = Texture.name;
return newTexInfo;
}
示例3: LoadTextureDXT
public static Texture2D LoadTextureDXT( string path, TextureFormat format, bool mipmap = true )
{
var a = Path.Combine( GenFilePaths.CoreModsFolderPath, LoadedModManager.LoadedMods.ToList().Find( s => s.name == "LT_RedistHeat" ).name );
var b = Path.Combine( a, "Textures" );
var filePath = Path.Combine( b, path + ".dds");
var bytes = File.ReadAllBytes( filePath );
if (format != TextureFormat.DXT1 && format != TextureFormat.DXT5)
throw new Exception("Invalid TextureFormat. Only DXT1 and DXT5 formats are supported by this method.");
var ddsSizeCheck = bytes[4];
if (ddsSizeCheck != 124)
throw new Exception("Invalid DDS DXT texture. Unable to read"); //this header byte should be 124 for DDS image files
var height = bytes[13] * 256 + bytes[12];
var width = bytes[17] * 256 + bytes[16];
var dxtBytes = new byte[bytes.Length - DDSHeaderSize];
Buffer.BlockCopy(bytes, DDSHeaderSize, dxtBytes, 0, bytes.Length - DDSHeaderSize);
var texture = new Texture2D(width, height, format, mipmap);
texture.LoadRawTextureData(dxtBytes);
texture.Apply();
return (texture);
}
示例4: createTexture
Texture2D createTexture(vectorx.ColorStorage storage)
{
var texture = new Texture2D(storage.width, storage.height, TextureFormat.RGBA32, false);
storage.data.memory.Seek (0, System.IO.SeekOrigin.Begin);
var bytes = storage.data.memory.ToArray ();
texture.LoadRawTextureData (bytes);
texture.Apply ();
return texture;
}
示例5: CreateTextureLocally
void CreateTextureLocally()
{
FillTextureDataLocally();
processedTexture = new Texture2D(512, 424, TextureFormat.BGRA32, false);
processedTexture.filterMode = FilterMode.Point;
processedTexture.LoadRawTextureData(textureData);
processedTexture.Apply();
riOutput.texture = processedTexture;
}
示例6: 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);
}
}
}
}
示例7: ToTexture2D
/// <summary>
/// Creates a Unity Texture2D from this Texture2DInfo. Can only be called from the main thread.
/// </summary>
public Texture2D ToTexture2D()
{
var texture = new Texture2D(width, height, format, hasMipmaps);
if(rawData != null)
{
texture.LoadRawTextureData(rawData);
texture.Apply();
}
return texture;
}
示例8: LoadDDSManual
public static Texture2D LoadDDSManual(string ddsPath)
{
try
{
byte[] ddsBytes = File.ReadAllBytes(ddsPath);
byte ddsSizeCheck = ddsBytes[4];
if (ddsSizeCheck != 124)
throw new System.Exception("Invalid DDS DXTn texture. Unable to read"); //this header byte should be 124 for DDS image files
int height = ddsBytes[13] * 256 + ddsBytes[12];
int width = ddsBytes[17] * 256 + ddsBytes[16];
byte DXTType = ddsBytes[87];
TextureFormat textureFormat = TextureFormat.DXT5;
if (DXTType == 49)
{
textureFormat = TextureFormat.DXT1;
// Debug.Log ("DXT1");
}
if (DXTType == 53)
{
textureFormat = TextureFormat.DXT5;
// Debug.Log ("DXT5");
}
int DDS_HEADER_SIZE = 128;
byte[] dxtBytes = new byte[ddsBytes.Length - DDS_HEADER_SIZE];
Buffer.BlockCopy(ddsBytes, DDS_HEADER_SIZE, dxtBytes, 0, ddsBytes.Length - DDS_HEADER_SIZE);
System.IO.FileInfo finf = new System.IO.FileInfo(ddsPath);
Texture2D texture = new Texture2D(width, height, textureFormat, false);
texture.LoadRawTextureData(dxtBytes);
texture.Apply();
texture.name = finf.Name;
return (texture);
}
catch (System.Exception ex)
{
Debug.LogError("Error: Could not load DDS");
return new Texture2D(8, 8);
}
}
示例9: Start
// Use this for initialization
void Start()
{
int width = srcTex.width;
int height = srcTex.height;
int blockSize = Squish.Squish.GetStorageRequirements(width, height, (int)Squish.Squish.Flags.kDxt1);
byte[] block = new byte[blockSize];
byte[] rgba = new byte[width * height * 4];
var srcColors = srcTex.GetPixels32();
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
var index = 4 * (x + y * width);
var c = srcColors[x + y * width];
rgba[index] = c.r;
rgba[index + 1] = c.g;
rgba[index + 2] = c.b;
rgba[index + 3] = c.a;
}
}
var startTime = Time.realtimeSinceStartup;
var ptrRgba = Marshal.AllocHGlobal(rgba.Length);
var ptrBlock = Marshal.AllocHGlobal(block.Length);
try {
Marshal.Copy(rgba, 0, ptrRgba, rgba.Length);
for (var i = 0; i < 10; i++)
Squish.Squish.CompressImage(ptrRgba, width, height, ptrBlock, (int)Squish.Squish.Flags.kDxt1);
Marshal.Copy(ptrBlock, block, 0, block.Length);
} finally {
Marshal.FreeHGlobal(ptrRgba);
Marshal.FreeHGlobal(ptrBlock);
}
var endTime = Time.realtimeSinceStartup;
Debug.Log("Elapsed : " + (endTime - startTime));
_dstTex = new Texture2D(width, height, TextureFormat.DXT1, false);
_dstTex.LoadRawTextureData(block);
//_dstTex.filterMode = FilterMode.Point;
_dstTex.Apply(false);
target.mainTexture = _dstTex;
Debug.Log(string.Format("Texture format={0} size={1} original={2}", _dstTex.format, blockSize, rgba.Length));
}
示例10: CreateTexture2DFromWebP
/// <summary>
///
/// </summary>
/// <param name="lData"></param>
/// <param name="lError"></param>
/// <returns></returns>
public static unsafe Texture2D CreateTexture2DFromWebP(byte[] lData, bool lMipmaps, bool lLinear, out Error lError, ScalingFunction scalingFunction = null )
{
lError = 0;
Texture2D lTexture2D = null;
int lWidth = 0, lHeight = 0;
GetWebPDimensions(lData, out lWidth, out lHeight);
byte[] lRawData = LoadRGBAFromWebP(lData, ref lWidth, ref lHeight, lMipmaps, out lError, scalingFunction);
if (lError == Error.Success)
{
lTexture2D = new Texture2D(lWidth, lHeight, TextureFormat.RGBA32, lMipmaps, lLinear);
lTexture2D.LoadRawTextureData(lRawData);
lTexture2D.Apply(lMipmaps, true);
}
return lTexture2D;
}
示例11: New
public static Texture2D New(int width, int height, Color32 color)
{
var texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
texture.filterMode = FilterMode.Point;
var pixels = new byte[width * height * 4];
for (int i = 0; i < pixels.Length; i += 4)
{
pixels[i + 0] = color.a;
pixels[i + 1] = color.r;
pixels[i + 2] = color.g;
pixels[i + 3] = color.b;
}
texture.LoadRawTextureData(pixels);
texture.Apply();
return texture;
}
示例12: LoadTexture2DRaw
private static Texture2D LoadTexture2DRaw(BinaryReader br, int w, int h)
{
Texture2D tex = new Texture2D(w, h, TextureFormat.RGBAHalf, false);
tex.wrapMode = TextureWrapMode.Repeat;
tex.filterMode = FilterMode.Bilinear;
int elementSize = sizeof(UInt16) * 4;
int dataSize = w * h * elementSize;
byte[] data = new byte[dataSize];
br.Read(data, 0, dataSize);
tex.LoadRawTextureData(data);
tex.Apply(false);
return tex;
}
示例13: LoadTextureFromGamedata
public void LoadTextureFromGamedata(string scd, string LocalPath, int Id, bool NormalMap = false){
SetPath();
if(!Directory.Exists(GameDataPath)){
Debug.LogError("Gamedata path not exist!");
return;
}
if(!Directory.Exists("temfiles")) Directory.CreateDirectory("temfiles");
ZipFile zf = null;
try {
FileStream fs = File.OpenRead(GameDataPath + scd);
zf = new ZipFile(fs);
char[] sep = ("/").ToCharArray();
string[] LocalSepPath = LocalPath.Split(sep);
string FileName = LocalSepPath[LocalSepPath.Length - 1];
foreach (ZipEntry zipEntry in zf) {
if (!zipEntry.IsFile) {
continue;
}
if(zipEntry.Name.ToLower() == LocalPath.ToLower() || zipEntry.Name == LocalPath.ToLower()){
//Debug.LogWarning("File found!");
byte[] buffer = new byte[4096]; // 4K is optimum
Stream zipStream = zf.GetInputStream(zipEntry);
int size = 4096;
using (FileStream streamWriter = File.Create("temfiles/" + FileName))
{
while (true)
{
size = zipStream.Read(buffer, 0, buffer.Length);
if (size > 0)
{
streamWriter.Write(buffer, 0, size);
}
else
{
break;
}
}
}
byte[] FinalTextureData = System.IO.File.ReadAllBytes("temfiles/" + FileName);
byte ddsSizeCheck = FinalTextureData[4];
if (ddsSizeCheck != 124)
throw new Exception("Invalid DDS DXTn texture. Unable to read"); //this header byte should be 124 for DDS image files
int height = FinalTextureData[13] * 256 + FinalTextureData[12];
int width = FinalTextureData[17] * 256 + FinalTextureData[16];
TextureFormat format;;
// Now this is made realy bad. I don't know how to check DDS texture format, so i check texture size and its all bytes length to check if there are 3 or 4 channels
float FormatFileSize = (float)FinalTextureData.Length / ((float)(width * height));
//Debug.LogWarning("Size: " + FormatFileSize);
if(FormatFileSize < 1){
format = TextureFormat.DXT1;
Debug.LogWarning(FileName + " is DXT1");
}
else if(FormatFileSize > 4){
format = TextureFormat.RGB24;
Debug.LogWarning(FileName + " is RGB24");
}
else{
format = TextureFormat.DXT5;
Debug.LogWarning(FileName + " is DXT5");
}
format = GetFormatOfDds("temfiles/" + FileName);
Texture2D texture = new Texture2D(width, height, format, true);
int DDS_HEADER_SIZE = 128;
byte[] dxtBytes = new byte[FinalTextureData.Length - DDS_HEADER_SIZE];
Buffer.BlockCopy(FinalTextureData, DDS_HEADER_SIZE, dxtBytes, 0, FinalTextureData.Length - DDS_HEADER_SIZE);
//texture.LoadImage(FinalTextureData);
texture.LoadRawTextureData(dxtBytes);
texture.Apply();
if(NormalMap){
Texture2D normalTexture = new Texture2D(height, width, TextureFormat.ARGB32, true);
Color theColour = new Color();
for (int x=0; x<texture.width; x++){
for (int y=0; y<texture.height; y++){
theColour.r = texture.GetPixel(x,y).r;
theColour.g = texture.GetPixel(x,y).g;
theColour.b = 1;
theColour.a = texture.GetPixel(x,y).g;
normalTexture.SetPixel(x,y, theColour);
}
}
//.........这里部分代码省略.........
示例14: RenderPageOne
private void RenderPageOne() {
if (GUILayout.Button("RequestCurrentStats()")) {
bool ret = SteamUserStats.RequestCurrentStats();
print("RequestCurrentStats() - " + ret);
}
{
bool ret = SteamUserStats.GetStat("NumGames", out m_NumGamesStat);
GUILayout.Label("GetStat(\"NumGames\", out m_NumGamesStat) - " + ret + " -- " + m_NumGamesStat);
}
{
bool ret = SteamUserStats.GetStat("FeetTraveled", out m_FeetTraveledStat);
GUILayout.Label("GetStat(\"FeetTraveled\", out m_FeetTraveledStat) - " + ret + " -- " + m_FeetTraveledStat);
}
if (GUILayout.Button("SetStat(\"NumGames\", m_NumGamesStat + 1)")) {
bool ret = SteamUserStats.SetStat("NumGames", m_NumGamesStat + 1);
print("SetStat(\"NumGames\", " + (m_NumGamesStat + 1) + ") - " + ret);
}
if (GUILayout.Button("SetStat(\"FeetTraveled\", m_FeetTraveledStat + 1)")) {
bool ret = SteamUserStats.SetStat("FeetTraveled", m_FeetTraveledStat + 1);
print("SetStat(\"FeetTraveled\", " + (m_FeetTraveledStat + 1) + ") - " + ret);
}
if (GUILayout.Button("UpdateAvgRateStat(\"AverageSpeed\", 100, 60.0)")) {
bool ret = SteamUserStats.UpdateAvgRateStat("AverageSpeed", 100, 60.0);
print("UpdateAvgRateStat(\"AverageSpeed\", 100, 60.0) - " + ret);
}
{
bool ret = SteamUserStats.GetAchievement("ACH_WIN_ONE_GAME", out m_AchievedWinOneGame);
GUILayout.Label("GetAchievement(\"ACH_WIN_ONE_GAME\", out m_AchievedWinOneGame) - " + ret + " -- " + m_AchievedWinOneGame);
}
if (GUILayout.Button("SetAchievement(\"ACH_WIN_ONE_GAME\")")) {
bool ret = SteamUserStats.SetAchievement("ACH_WIN_ONE_GAME");
print("SetAchievement(\"ACH_WIN_ONE_GAME\") - " + ret);
}
if (GUILayout.Button("ClearAchievement(\"ACH_WIN_ONE_GAME\")")) {
bool ret = SteamUserStats.ClearAchievement("ACH_WIN_ONE_GAME");
print("ClearAchievement(\"ACH_WIN_ONE_GAME\") - " + ret);
}
{
bool Achieved;
uint UnlockTime;
bool ret = SteamUserStats.GetAchievementAndUnlockTime("ACH_WIN_ONE_GAME", out Achieved, out UnlockTime);
GUILayout.Label("GetAchievementAndUnlockTime(\"ACH_WIN_ONE_GAME\", out Achieved, out UnlockTime) - " + ret + " -- " + Achieved + " -- " + UnlockTime);
}
if (GUILayout.Button("StoreStats()")) {
bool ret = SteamUserStats.StoreStats();
print("StoreStats() - " + ret);
}
if (GUILayout.Button("GetAchievementIcon(\"ACH_WIN_ONE_GAME\")")) {
int icon = SteamUserStats.GetAchievementIcon("ACH_WIN_ONE_GAME");
print("SteamUserStats.GetAchievementIcon(\"ACH_WIN_ONE_GAME\") - " + icon);
if (icon != 0) {
uint Width = 0;
uint Height = 0;
bool ret = SteamUtils.GetImageSize(icon, out Width, out Height);
if (ret && Width > 0 && Height > 0) {
byte[] RGBA = new byte[Width * Height * 4];
ret = SteamUtils.GetImageRGBA(icon, RGBA, RGBA.Length);
if (ret) {
m_Icon = new Texture2D((int)Width, (int)Height, TextureFormat.RGBA32, false, true);
m_Icon.LoadRawTextureData(RGBA);
m_Icon.Apply();
}
}
}
}
GUILayout.Label("GetAchievementDisplayAttribute(\"ACH_WIN_ONE_GAME\", \"name\") : " + SteamUserStats.GetAchievementDisplayAttribute("ACH_WIN_ONE_GAME", "name"));
if (GUILayout.Button("IndicateAchievementProgress(\"ACH_WIN_100_GAMES\", 10, 100)")) {
bool ret = SteamUserStats.IndicateAchievementProgress("ACH_WIN_100_GAMES", 10, 100);
print("IndicateAchievementProgress(\"ACH_WIN_100_GAMES\", 10, 100) - " + ret);
}
GUILayout.Label("GetNumAchievements() : " + SteamUserStats.GetNumAchievements());
GUILayout.Label("GetAchievementName(0) : " + SteamUserStats.GetAchievementName(0));
if (GUILayout.Button("RequestUserStats(SteamUser.GetSteamID())")) {
SteamAPICall_t handle = SteamUserStats.RequestUserStats(new CSteamID(76561197991230424)); //rlabrecque
UserStatsReceived.Set(handle);
print("RequestUserStats(" + SteamUser.GetSteamID() + ") - " + handle);
}
{
int Data;
bool ret = SteamUserStats.GetUserStat(new CSteamID(76561197991230424), "NumWins", out Data); //rlabrecque
GUILayout.Label("GetUserStat(SteamUser.GetSteamID(), \"NumWins\", out Data) : " + ret + " -- " + Data);
}
//.........这里部分代码省略.........
示例15: GetContractIcon
/// <summary>
/// Gets the contract icon for the given id and seed (color).
/// </summary>
/// <param name="url">URL of the icon</param>
/// <param name="seed">Seed to use for generating the color</param>
/// <returns>The texture</returns>
public static Texture2D GetContractIcon(string url, int seed)
{
// Check cache for texture
Texture2D texture;
Color color = SystemUtilities.RandomColor(seed, 1.0f, 1.0f, 1.0f);
if (!contractIcons.ContainsKey(url))
{
contractIcons[url] = new Dictionary<Color, Texture2D>();
}
if (!contractIcons[url].ContainsKey(color))
{
Texture2D baseTexture = ContractDefs.sprites[url].texture;
try
{
Texture2D loadedTexture = null;
string path = (url.Contains('/') ? "GameData/" : "GameData/Squad/Contracts/Icons/") + url;
// PNG loading
if (File.Exists(path + ".png"))
{
path += ".png";
loadedTexture = new Texture2D(baseTexture.width, baseTexture.height, TextureFormat.RGBA32, false);
loadedTexture.LoadImage(File.ReadAllBytes(path.Replace('/', Path.DirectorySeparatorChar)));
}
// DDS loading
else if (File.Exists(path + ".dds"))
{
path += ".dds";
BinaryReader br = new BinaryReader(new MemoryStream(File.ReadAllBytes(path)));
if (br.ReadUInt32() != DDSValues.uintMagic)
{
throw new Exception("Format issue with DDS texture '" + path + "'!");
}
DDSHeader ddsHeader = new DDSHeader(br);
if (ddsHeader.ddspf.dwFourCC == DDSValues.uintDX10)
{
DDSHeaderDX10 ddsHeaderDx10 = new DDSHeaderDX10(br);
}
TextureFormat texFormat;
if (ddsHeader.ddspf.dwFourCC == DDSValues.uintDXT1)
{
texFormat = UnityEngine.TextureFormat.DXT1;
}
else if (ddsHeader.ddspf.dwFourCC == DDSValues.uintDXT3)
{
texFormat = UnityEngine.TextureFormat.DXT1 | UnityEngine.TextureFormat.Alpha8;
}
else if (ddsHeader.ddspf.dwFourCC == DDSValues.uintDXT5)
{
texFormat = UnityEngine.TextureFormat.DXT5;
}
else
{
throw new Exception("Unhandled DDS format!");
}
loadedTexture = new Texture2D((int)ddsHeader.dwWidth, (int)ddsHeader.dwHeight, texFormat, false);
loadedTexture.LoadRawTextureData(br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position)));
}
else
{
throw new Exception("Couldn't find file for icon '" + url + "'");
}
Color[] pixels = loadedTexture.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] *= color;
}
texture = new Texture2D(baseTexture.width, baseTexture.height, TextureFormat.RGBA32, false);
texture.SetPixels(pixels);
texture.Apply(false, false);
contractIcons[url][color] = texture;
UnityEngine.Object.Destroy(loadedTexture);
}
catch (Exception e)
{
Debug.LogError("WaypointManager: Couldn't create texture for '" + url + "'!");
Debug.LogException(e);
texture = contractIcons[url][color] = baseTexture;
}
}
else
{
texture = contractIcons[url][color];
}
return texture;
}