Information about image's frame.

This is a base class, which keeps basic information about image, like its width, height, etc. Classes, which inherit from this, may define more properties describing certain image formats.

Inheritance: ICloneable
Example #1
0
        /// <summary>
        /// Decode specified frame.
        /// </summary>
        /// 
        /// <param name="frameIndex">Image frame to decode.</param>
        /// <param name="imageInfo">Receives information about decoded frame.</param>
        /// 
        /// <returns>Returns decoded frame.</returns>
        /// 
        /// <exception cref="NullReferenceException">No image stream was opened previously.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Stream does not contain frame with specified index.</exception>
        /// <exception cref="ArgumentException">The stream contains invalid (broken) PNM image.</exception>
        /// 
        public Bitmap DecodeFrame( int frameIndex, out ImageInfo imageInfo )
        {
            // check requested frame index
            if ( frameIndex != 0 )
            {
                throw new ArgumentOutOfRangeException( "Currently opened stream does not contain frame with specified index." );
            }

            // seek to the required frame
            stream.Seek( dataPosition, SeekOrigin.Begin );

            // read required frame
            Bitmap image = ReadImageFrame( stream, this.imageInfo );

            // provide also frame information
            imageInfo = (PNMImageInfo) this.imageInfo.Clone( );

            return image;
        }
Example #2
0
        /// <summary>
        /// Decode specified frame.
        /// </summary>
        /// 
        /// <param name="frameIndex">Image frame to decode.</param>
        /// <param name="imageInfo">Receives information about decoded frame.</param>
        /// 
        /// <returns>Returns decoded frame.</returns>
        /// 
        /// <exception cref="NullReferenceException">No image stream was opened previously.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Stream does not contain frame with specified index.</exception>
        /// <exception cref="ArgumentException">The stream contains invalid (broken) FITS image.</exception>
        /// 
        public Bitmap DecodeFrame( int frameIndex, out ImageInfo imageInfo )
        {
            // check requested frame index
            if ( frameIndex >= this.imageInfo.TotalFrames )
            {
                throw new ArgumentOutOfRangeException( "Currently opened stream does not contain frame with specified index." );
            }

            // seek to the required frame
            stream.Seek( dataPosition + frameIndex * this.imageInfo.Width * this.imageInfo.Height *
                Math.Abs( this.imageInfo.OriginalBitsPerPixl ) / 8, SeekOrigin.Begin );

            // read required frame
            Bitmap image = ReadImageFrame( stream, this.imageInfo );

            // provide also frame information
            imageInfo = (FITSImageInfo) this.imageInfo.Clone( );
            imageInfo.FrameIndex = frameIndex;

            return image;
        }
Example #3
0
        /// <summary>
        /// Decode first frame for the specified file.
        /// </summary>
        /// 
        /// <param name="fileName">File name to read image from.</param>
        /// <param name="imageInfo">Information about the decoded image.</param>
        /// 
        /// <returns>Return decoded image. In the case if file format support multiple
        /// frames, the method return the first frame.</returns>
        /// 
        /// <remarks><para>The method uses table of registered image decoders to find the one,
        /// which should be used for the specified file. If there is not appropriate decoder
        /// found, the method uses default .NET's image decoding routine (see
        /// <see cref="System.Drawing.Image.FromFile( string )"/>).</para></remarks>
        /// 
        public static Bitmap DecodeFromFile( string fileName, out ImageInfo imageInfo )
        {
            Bitmap bitmap = null;

            string fileExtension = Path.GetExtension( fileName ).ToLower( );

            if ( ( fileExtension != string.Empty ) && ( fileExtension.Length != 0 ) )
            {
                fileExtension = fileExtension.Substring( 1 );

                if ( decoders.ContainsKey( fileExtension ) )
                {
                    IImageDecoder decoder = decoders[fileExtension];

                    // open stream
                    FileStream stream = new FileStream( fileName, FileMode.Open );
                    // open decoder
                    decoder.Open( stream );
                    // read the first frame
                    bitmap = decoder.DecodeFrame( 0, out imageInfo );

                    // close decoder and stream
                    decoder.Close( );
                    stream.Close( );
                    stream.Dispose( );

                    return bitmap;
                }
            }

            // use default .NET's image decoding routine
            bitmap = (Bitmap) Image.FromFile( fileName );

            imageInfo = new ImageInfo( bitmap.Width, bitmap.Height, Image.GetPixelFormatSize( bitmap.PixelFormat ), 0, 1 );

            return bitmap;
        }