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 ); }
/// <summary> /// Resize a 2D image, applying the appropriate filter. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="filter"></param> public void Resize( int width, int height, ImageFilter filter ) { // resizing dynamic images is not supported //TODO : Debug.Assert( this._bAutoDelete); Debug.Assert( this.Depth == 1 ); // reassign buffer to temp image, make sure auto-delete is true Image temp = new Image(); temp.FromDynamicImage( buffer, width, height, 1, format ); // do not delete[] m_pBuffer! temp will destroy it // set new dimensions, allocate new buffer this.width = width; this.height = height; size = PixelUtil.GetMemorySize( Width, Height, 1, Format ); buffer = new byte[ size ]; numMipMaps = 0; // Loses precomputed mipmaps // scale the image from temp into our resized buffer Scale( temp.GetPixelBox( 0, 0 ), GetPixelBox( 0, 0 ), filter ); }
public void LoadImage( Image img ) { var pBox = img.GetPixelBox(); Blit( ref pBox ); }