本文整理汇总了C#中PixelFormat.Write方法的典型用法代码示例。如果您正苦于以下问题:C# PixelFormat.Write方法的具体用法?C# PixelFormat.Write怎么用?C# PixelFormat.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PixelFormat
的用法示例。
在下文中一共展示了PixelFormat.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/// <summary>Save the texture to the file.</summary>
/// <param name="texture"></param>
/// <param name="writer"></param>
public void Save(Texture texture, BinaryWriter writer)
{
Texture2D texture2d = texture as Texture2D;
Vector3i dimensions;
int pitchOrLinearSize;
Flags flags = RequiredFlags | Flags.MipMapCount;
int mipMapCount;
dimensions = new Vector3i(texture2d.Dimensions, 1);
for (mipMapCount = 0; texture2d.Levels[mipMapCount].Dimensions.Sum != 0; mipMapCount++) ;
if (texture.Format.IsCompressed) {
pitchOrLinearSize = texture.Format.AlignedByteSize(dimensions);
flags |= Flags.LinearSize;
} else {
pitchOrLinearSize = texture.Format.AlignedBytePitch(dimensions.X);
flags |= Flags.Pitch;
}
for (int index = 0; index < Magic.Length; index++)
writer.Write((byte)Magic[index]);
writer.Write(HeaderSize);
writer.Write((int)flags);
writer.Write(dimensions.X);
writer.Write(dimensions.Y);
writer.Write(pitchOrLinearSize);
writer.Write(dimensions.Z);
writer.Write(mipMapCount);
for (int i = 0; i < 11; i++)
writer.Write(0); // Reserved
var pixelFormat = new PixelFormat(texture.Format);
pixelFormat.Write(writer);
writer.Write((int)(Caps.Texture));
writer.Write((int)(Caps2.None));
writer.Write(0); // DDSCaps3, reserved
writer.Write(0); // DDSCaps4, reserved
writer.Write(0); // Reserved
byte[] data = new byte[texture.Format.AlignedByteSize(dimensions)];
for (int level = 0; level < mipMapCount; level++) {
TextureLevel textureLevel = texture2d.Surface.Levels[level];
textureLevel.Read(data, 0, texture.Format);
int size = texture.Format.AlignedByteSize(textureLevel.Dimensions);
writer.Write(data, 0, size);
}
#if false
Texture2D texture = new Texture2D();//format, new Vector2i(width, height));
for (int level = 0; level < mipMapCount; level++) {
if (reader.Read(data, 0, linearSize) != linearSize)
throw new InvalidDataException();
texture.Surface.Levels[level].DataCompressed(format, new Vector2i(width, height), data);
width = (width + 1) / 2;
height = (height + 1) / 2;
linearSize = format.AlignedByteSize(width, height);
}
texture.Name = path;
return texture;
#endif
}