[英]Unity3d convert Texture2d into bitmap format
I had made an attempt to get this done but unfortunately I am coming up short not sure what I am doing wrong. 我已经尝试完成此操作,但是很不幸,我无法确定自己在做什么错。
private void CreateMovie(List<Texture2D> textures, string fileName, int frameRate)
{
var writer = new AviWriter(fileName + ".avi")
{
FramesPerSecond = frameRate,
EmitIndex1 = true
};
var stream = writer.AddVideoStream();
stream.Width = _images[0].width;
stream.Height = _images[0].height;
stream.Codec = KnownFourCCs.Codecs.Uncompressed;
stream.BitsPerPixel = BitsPerPixel.Bpp32;
int count = 0;
while (count < textures.Count)
{
byte[] byteArray = textures[count].GetRawTextureData();
stream.WriteFrame(false, byteArray, 0, byteArray.Length);
count++;
}
writer.Close();
}
Once I write the bytes to file and try to open it I get the file is in a unknown format. 一旦我将字节写入文件并尝试打开它,我得到的文件是未知格式。
Can you post your code for writing to the texture? 您可以张贴代码以写入纹理吗?
To convert your Texture to a different format, you will need to create a new Texture with the desired format, then write the data to the texture. 要将纹理转换为其他格式,您将需要使用所需的格式创建一个新的纹理,然后将数据写入该纹理。
Use the following constructor: public Texture2D(int width, int height, TextureFormat textureFormat = TextureFormat.RGBA32, bool mipChain = true, bool linear = false);
使用以下构造函数:
public Texture2D(int width, int height, TextureFormat textureFormat = TextureFormat.RGBA32, bool mipChain = true, bool linear = false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.