Axiom.Media.Image.Save C# (CSharp) Method

Save() public method

Saves the Image as a file
The codec used to save the file is determined by the extension of the filename passed in Invalid or unrecognized extensions will throw an exception.
public Save ( String filename ) : void
filename String Filename to save as
return void
		public void Save( String filename )
		{
			if ( this.buffer == null )
			{
				throw new Exception( "No image data loaded" );
			}

			String strExt = "";
			int pos = filename.LastIndexOf( "." );
			if ( pos == -1 )
				throw new Exception( "Unable to save image file '" + filename + "' - invalid extension." );

			while ( pos != filename.Length - 1 )
				strExt += filename[ ++pos ];

			ICodec pCodec = CodecManager.Instance.GetCodec( strExt );
			if ( pCodec == null )
				throw new Exception( "Unable to save image file '" + filename + "' - invalid extension." );

			ImageCodec.ImageData imgData = new ImageCodec.ImageData();
			imgData.format = Format;
			imgData.height = Height;
			imgData.width = Width;
			imgData.depth = Depth;
			imgData.size = Size;
			// Wrap memory, be sure not to delete when stream destroyed
			MemoryStream wrapper = new MemoryStream( buffer );

			pCodec.EncodeToFile( wrapper, filename, imgData );
		}

Usage Example

Beispiel #1
0
        private void SaveToDisk( Texture tp, string filename )
        {
          // Declare buffer
            int buffSize = tp.Width * tp.Height * tp.Depth * 4;
            byte[] data = new byte[buffSize];
          

          // Setup Image with correct settings
          Image i = new Image();
          i.FromDynamicImage(data, tp.Width, tp.Height, tp.Depth,tp.Format);
          
          // Copy Texture buffer contents to image buffer
          HardwarePixelBuffer buf = tp.GetBuffer();      
          PixelBox destBox = i.GetPixelBox(0,0);
          buf.BlitToMemory(destBox);
          
          // Save to disk!
          i.Save( @"C:\" + filename );
        }