///////////////////////////////////////// /// <summary> /// Loads an image file. /// </summary> /// <param name="virtualFileName">The virtual file name.</param> /// <param name="data">The image data.</param> /// <param name="size">The image size.</param> /// <param name="depth">The image depth (in 3d images, numbers of layers, otherwhise 1).</param> /// <param name="format">Pixel format.</param> /// <param name="numFaces">The number of faces the image data has inside (6 for cubemaps, 1 otherwise).</param> /// <param name="numMipmaps">The number of mipmaps the image data has inside.</param> /// <param name="error">Output error string.</param> /// <returns><b>true</b> if image is loaded; otherwise, <b>false</b>.</returns> public static bool LoadFromVirtualFile(string virtualFileName, out byte[] data, out Vector2I size, out int depth, out PixelFormat format, out int numFaces, out int numMipmaps, out string error) { unsafe { IntPtr pData; int dataSize; int width; int height; IntPtr errPointer; bool result = OgreImageManager.loadFromFile(RenderingSystem.realRoot, virtualFileName, out pData, out dataSize, out width, out height, out depth, out format, out numFaces, out numMipmaps, out errPointer); string err = OgreNativeWrapper.GetOutString(errPointer); error = null; data = null; size = new Vector2I(width, height); if (err != null) { error = string.Format("Loading file failed \"{0}\" ({1}).", virtualFileName, err); } if (pData != IntPtr.Zero) { data = new byte[dataSize]; Marshal.Copy(pData, data, 0, data.Length); OgreImageManager.freeData(RenderingSystem.realRoot, pData); } return(result); } }
/// <summary> /// Loads an image from buffer. /// </summary> /// <param name="sourceBuffer">The source buffer.</param> /// <param name="fileType">The file type (file extension).</param> /// <param name="data">The image data.</param> /// <param name="size">The image size.</param> /// <param name="depth">The image depth (in 3d images, numbers of layers, otherwhise 1).</param> /// <param name="format">Pixel format.</param> /// <param name="numFaces">The number of faces the image data has inside (6 for cubemaps, 1 otherwise).</param> /// <param name="numMipmaps">The number of mipmaps the image data has inside.</param> /// <param name="error">Output error string.</param> /// <returns><b>true</b> if image is loaded; otherwise, <b>false</b>.</returns> public static bool LoadFromBuffer(byte[] sourceBuffer, string fileType, out byte[] data, out Vector2I size, out int depth, out PixelFormat format, out int numFaces, out int numMipmaps, out string error) { unsafe { IntPtr pData; int dataSize; int width; int height; IntPtr errPointer; bool result; fixed(byte *pSourceBuffer = sourceBuffer) { result = OgreImageManager.loadFromBuffer(RenderingSystem.realRoot, (IntPtr)pSourceBuffer, sourceBuffer.Length, fileType, out pData, out dataSize, out width, out height, out depth, out format, out numFaces, out numMipmaps, out errPointer); } string err = OgreNativeWrapper.GetOutString(errPointer); error = null; data = null; size = new Vector2I(width, height); if (err != null) { error = string.Format("Loading file from buffer failed ({0}).", err); } if (pData != IntPtr.Zero) { data = new byte[dataSize]; Marshal.Copy(pData, data, 0, data.Length); OgreImageManager.freeData(RenderingSystem.realRoot, pData); } return(result); } }