Axiom.Plugins.DevILCodecs.ILImageCodec.EncodeToFile C# (CSharp) Method

EncodeToFile() public method

public EncodeToFile ( Stream input, string fileName, object codecData ) : void
input Stream
fileName string
codecData object
return void
		public override void EncodeToFile( Stream input, string fileName, object codecData )
		{
			int imageID;

			// create and bind a new image
			Il.ilGenImages( 1, out imageID );
			Il.ilBindImage( imageID );

			byte[] buffer = new byte[ input.Length ];
			input.Read( buffer, 0, buffer.Length );

			ImageData data = (ImageData)codecData;

			GCHandle bufHandle = GCHandle.Alloc( buffer, GCHandleType.Pinned );
			PixelBox src = new PixelBox( data.width, data.height, data.depth, data.format, bufHandle.AddrOfPinnedObject() );

			try
			{
				// Convert image from Axiom to current IL image
				ILUtil.ConvertToIL( src );
			}
			catch ( Exception ex )
			{
				LogManager.Instance.Write( "IL Failed image conversion :", ex.Message );
			}

			// flip the image
			Ilu.iluFlipImage();

			// save the image to file
			Il.ilSaveImage( fileName );

			if ( bufHandle.IsAllocated )
				bufHandle.Free();

			int error = Il.ilGetError();

			if ( error != Il.IL_NO_ERROR )
				LogManager.Instance.Write( "IL Error, could not save file: {0} : {1}", fileName, Ilu.iluErrorString( error ) );
		}