private void ConvertPNGToTex(string inputFile, FileStream outputStream) { TEXFile.PixelFormat PixelFormat = (TEXFile.PixelFormat)Enum.Parse(typeof(TEXFile.PixelFormat), this.pixelFormatComboBox.Text); InterpolationMode interpolationMode = (InterpolationMode)Enum.Parse(typeof(InterpolationMode), this.mipmapFilterComboBox.Text); Bitmap inputImage = (Bitmap)Bitmap.FromFile(inputFile); inputImage.RotateFlip(RotateFlipType.RotateNoneFlipY); bool GenerateMipmaps = generateMipmapsCheckBox.Checked; List <Mipmap> Mipmaps = new List <Mipmap>(); bool preMultiplyAlpha = preMultiplyAlphaCheckBox.Checked; Mipmaps.Add(GenerateMipmap(inputImage, PixelFormat, preMultiplyAlpha)); if (GenerateMipmaps) { var width = inputImage.Width; var height = inputImage.Height; while (Math.Max(width, height) > 1) { width = Math.Max(1, width >> 1); height = Math.Max(1, height >> 1); Mipmaps.Add(GenerateMipmap(inputImage, PixelFormat, width, height, interpolationMode, preMultiplyAlpha)); } } TEXFile outputTEXFile = new TEXFile(); outputTEXFile.File.Header.Platform = 0; outputTEXFile.File.Header.PixelFormat = (uint)PixelFormat; outputTEXFile.File.Header.TextureType = (uint)EnumHelper <TEXFile.TextureType> .GetValueFromDescription(this.textureTypeComboBox.Text); outputTEXFile.File.Header.NumMips = (uint)Mipmaps.Count; outputTEXFile.File.Header.Flags = 0; MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); foreach (Mipmap mip in Mipmaps) { writer.Write(mip.Width); writer.Write(mip.Height); writer.Write(mip.Pitch); writer.Write((uint)mip.ARGBData.Length); } foreach (Mipmap mip in Mipmaps) { writer.Write(mip.ARGBData); } writer.Close(); outputTEXFile.File.Raw = ms.ToArray(); outputTEXFile.SaveFile(outputStream); }