FromDynamicImage() публичный Метод

Loads raw image data from a byte array.
public FromDynamicImage ( byte buffer, int width, int height, PixelFormat format ) : Image
buffer byte Raw image buffer.
width int Width of this image data (in pixels).
height int Height of this image data (in pixels).
format PixelFormat Pixel format used in this texture.
Результат Image
Пример #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 );
        }
Пример #2
0
		/// <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 );
		}
        private void CreateTileData()
        {
            if (textureName.Equals("zero.png"))
            {
                textureName = string.Format("{0}_x{1}y{2}.{3}", parent.BaseName, m_tileLocationX, m_loadTileZ,
                                            parent.MosaicDesc.FileExt);
            }

            Image   textureImage;
            Texture texture = TextureManager.Instance.GetByName(textureName);

            if (ResourceManager.HasCommonResourceData(textureName))
            {
                Stream s = ResourceManager.FindCommonResourceData(textureName);
                textureImage = Image.FromStream(s, parent.MosaicDesc.FileExt);
                s.Close();
            }
            else
            {
                // Create a new image
                int    bpp    = PixelUtil.GetNumElemBytes(DEFAULT_IMAGE_FORMAT);
                byte[] buffer = new byte[tileSizeSamples * tileSizeSamples * bpp];
                textureImage = Image.FromDynamicImage(buffer, tileSizeSamples, tileSizeSamples, DEFAULT_IMAGE_FORMAT);
                Modified     = true;
            }

            // Cause the texture image to get refreshed
            dirtyImage       = true;
            dirtyArea.X      = 0;
            dirtyArea.Y      = 0;
            dirtyArea.Width  = textureImage.Width;
            dirtyArea.Height = textureImage.Height;

            // Popupate the tileData from the image
            switch (textureImage.Format)
            {
            case PixelFormat.A8:
            case PixelFormat.L8:
                tileData = new TileData8(textureImage);
                break;

            case PixelFormat.L16:
                tileData = new TileData16(textureImage);
                break;

            case PixelFormat.R8G8B8:
            case PixelFormat.B8G8R8:
                tileData = new TileData24(textureImage);
                break;

            case PixelFormat.A8B8G8R8:
            case PixelFormat.A8R8G8B8:
            case PixelFormat.B8G8R8A8:
            case PixelFormat.R8G8B8A8:
            case PixelFormat.X8R8G8B8:
            case PixelFormat.X8B8G8R8:
                tileData = new TileData32(textureImage);
                break;

            default:
                throw new InvalidDataException("Unexpected pixel format: " + textureImage.Format);
            }
        }