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

GetPixelBox() public method

Get a PixelBox encapsulating the image data of a mipmap
public GetPixelBox ( int face, int mipmap ) : PixelBox
face int
mipmap int
return PixelBox
		public PixelBox GetPixelBox( int face, int mipmap )
		{
			if ( mipmap > numMipMaps )
				throw new IndexOutOfRangeException();
			if ( face > this.NumFaces )
				throw new IndexOutOfRangeException();
			// Calculate mipmap offset and size
			int width = this.Width;
			int height = this.Height;
			int depth = this.Depth;
			int faceSize = 0; // Size of one face of the image
			int offset = 0;
			for ( int mip = 0; mip < mipmap; ++mip )
			{
				faceSize = PixelUtil.GetMemorySize( width, height, depth, this.Format );
				// Skip all faces of this mipmap
				offset += faceSize * this.NumFaces;
				// Half size in each dimension
				if ( width != 1 )
					width /= 2;
				if ( height != 1 )
					height /= 2;
				if ( depth != 1 )
					depth /= 2;
			}
			// We have advanced to the desired mipmap, offset to right face
			faceSize = PixelUtil.GetMemorySize( width, height, depth, this.Format );
			offset += faceSize * face;
			// Return subface as pixelbox
			if ( bufPtr != IntPtr.Zero )
			{
				return new PixelBox( width, height, depth, this.Format, bufPtr );
			}
			else
			{
				throw new AxiomException( "Image wasn't loaded, can't get a PixelBox." );
			}
		}

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 );
        }
All Usage Examples Of Axiom.Media.Image::GetPixelBox