ME3Explorer.Unreal.Classes.Texture2D.extractImage C# (CSharp) Method

extractImage() public method

public extractImage ( ImageInfo imgInfo, string archiveDir = null, string fileName = null ) : void
imgInfo ImageInfo
archiveDir string
fileName string
return void
        public void extractImage(ImageInfo imgInfo, string archiveDir = null, string fileName = null)
        {
            ImageFile imgFile;
            if (fileName == null)
            {
                fileName = texName + "_" + imgInfo.imgSize + getFileFormat();
            }

            byte[] imgBuffer;

            switch (imgInfo.storageType)
            {
                case storage.pccSto:
                    imgBuffer = new byte[imgInfo.uncSize];
                    Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize);
                    break;
                case storage.arcCpr:
                case storage.arcUnc:
                    string archivePath = archiveDir + "\\" + arcName + ".tfc";
                    if (!File.Exists(archivePath))
                    {
                        throw new FileNotFoundException("Texture archive not found in " + archivePath);
                    }

                    using (FileStream archiveStream = File.OpenRead(archivePath))
                    {
                        archiveStream.Seek(imgInfo.offset, SeekOrigin.Begin);
                        if (imgInfo.storageType == storage.arcCpr)
                        {
                            imgBuffer = ZBlock.Decompress(archiveStream, imgInfo.cprSize);
                        }
                        else
                        {
                            imgBuffer = new byte[imgInfo.uncSize];
                            archiveStream.Read(imgBuffer, 0, imgBuffer.Length);
                        }
                    }
                    break;
                default:
                    throw new FormatException("Unsupported texture storage type");
            }

            if (getFileFormat() == ".dds")
                imgFile = new DDS(fileName, imgInfo.imgSize, texFormat, imgBuffer);
            else
                imgFile = new TGA(fileName, imgInfo.imgSize, texFormat, imgBuffer);

            byte[] saveImg = imgFile.ToArray();
            using (FileStream outputImg = new FileStream(imgFile.fileName, FileMode.Create, FileAccess.Write))
                outputImg.Write(saveImg, 0, saveImg.Length);
        }

Same methods

Texture2D::extractImage ( string strImgSize, string archiveDir = null, string fileName = null ) : void

Usage Example

Example #1
0
        public void ReadTextureParams(byte[] raw)
        {
            int count = BitConverter.ToInt32(raw, 24);
            int pos   = 28;

            for (int i = 0; i < count; i++)
            {
                List <PropertyReader.Property> tp = PropertyReader.ReadProp(pcc, raw, pos);
                string       name = pcc.getNameEntry(tp[1].Value.IntValue);
                int          Idx  = tp[2].Value.IntValue;
                TextureParam t    = new TextureParam();
                t.Desc     = name;
                t.TexIndex = Idx;
                if (name.ToLower().Contains("diffuse") && Idx > 0)
                {
                    Texture2D           tex = new Texture2D(pcc, Idx - 1);
                    string              loc = Path.GetDirectoryName(Application.ExecutablePath);
                    Texture2D.ImageInfo inf = new Texture2D.ImageInfo();
                    for (int j = 0; j < tex.imgList.Count(); j++)
                    {
                        if (tex.imgList[j].storageType != Texture2D.storage.empty)
                        {
                            inf = tex.imgList[j];
                            break;
                        }
                    }
                    if (File.Exists(loc + "\\exec\\TempTex.dds"))
                    {
                        File.Delete(loc + "\\exec\\TempTex.dds");
                    }
                    tex.extractImage(inf, ME3Directory.cookedPath, loc + "\\exec\\TempTex.dds");
                    if (File.Exists(loc + "\\exec\\TempTex.dds"))
                    {
                        try
                        {
                            t.Texture = TextureLoader.FromFile(Meshplorer.Preview3D.device, loc + "\\exec\\TempTex.dds");
                        }
                        catch (Direct3DXException e)
                        {
                        }
                    }
                    else
                    {
                        t.Texture = null;
                    }
                }
                else
                {
                    t.Texture = null;
                }
                Textures.Add(t);
                pos = tp[tp.Count - 1].offend;
            }
        }
All Usage Examples Of ME3Explorer.Unreal.Classes.Texture2D::extractImage