AmaroK86.ImageFormat.DDS.ToArray C# (CSharp) Метод

ToArray() публичный Метод

public ToArray ( ) : byte[]
Результат byte[]
        public override byte[] ToArray()
        {
            int size = Marshal.SizeOf(DDSHeader);
            if (size != headData.Length)
                throw new FormatException("Incorrect DXT header size");
            byte[] head = new byte[size];
            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(DDSHeader, ptr, true);
            Marshal.Copy(ptr, head, 0, size);
            Marshal.FreeHGlobal(ptr);

            byte[] total = new byte[headSize + dataSize];
            head.CopyTo(total, 0);
            imgData.CopyTo(total, headSize);
            return total;
        }
    }

Usage Example

Пример #1
0
        public byte[] extractImage(ImageInfo imgInfo, bool NoOutput, 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 = GetTexArchive(archiveDir);
                    string archivePath = FullArcPath;
                    if (String.IsNullOrEmpty(archivePath))
                        GetTexArchive(archiveDir);
                    if (archivePath == null)
                        throw new FileNotFoundException("Texture archive not found!");
                    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, Textures.Methods.StringifyFormat(texFormat), imgBuffer);
            //else
            //    imgFile = new TGA(fileName, imgInfo.imgSize, texFormat, imgBuffer);

            byte[] saveImg = imgFile.ToArray();

            if (!NoOutput)
                using (FileStream outputImg = new FileStream(imgFile.fileName, FileMode.Create, FileAccess.Write))
                    outputImg.Write(saveImg, 0, saveImg.Length);

            return saveImg;
        }
All Usage Examples Of AmaroK86.ImageFormat.DDS::ToArray