BitmapFrameEncode.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / Media / Imaging / BitmapFrameEncode.cs / 1 / BitmapFrameEncode.cs

                            //------------------------------------------------------------------------------ 
//  Microsoft Avalon
//  Copyright (c) Microsoft Corporation
//
//  File: BitmapFrameEncode.cs 
//
//----------------------------------------------------------------------------- 
 
using System;
using System.Collections; 
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection; 
using MS.Internal;
using System.Diagnostics; 
using System.Windows.Media; 
using System.Globalization;
using System.Security; 
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Windows.Media.Animation;
using System.Windows.Media.Composition; 
using System.Windows.Media.Imaging;
using MS.Win32; 
 
namespace System.Windows.Media.Imaging
{ 
    #region BitmapFrameEncode

    /// 
    /// BitmapFrameEncode abstract class 
    /// 
    internal sealed class BitmapFrameEncode : BitmapFrame 
    { 

        #region Constructors 

        /// 
        /// Internal constructor
        ///  
        /// 
        /// SecurityCritical: Accesses unmanaged resources (_wicSource) 
        /// SecurityTreatAsSafe: Inputs are verified and _wicSource and the get is Critical 
        /// 
        [SecurityCritical, SecurityTreatAsSafe] 
        internal BitmapFrameEncode(
            BitmapSource source,
            BitmapSource thumbnail,
            BitmapMetadata metadata, 
            ReadOnlyCollection colorContexts
            ) 
            : base(true) 
        {
            _bitmapInit.BeginInit(); 

            Debug.Assert(source != null);
            _source = source;
            WicSourceHandle = _source.WicSourceHandle; 
            IsSourceCached = _source.IsSourceCached;
            _isColorCorrected = _source._isColorCorrected; 
            _thumbnail = thumbnail; 
            _readOnlycolorContexts = colorContexts;
            InternalMetadata = metadata; 
            _syncObject = source.SyncObject;
            _bitmapInit.EndInit();

            FinalizeCreation(); 
        }
 
        ///  
        /// Do not allow construction
        /// This will be called for cloning 
        /// 
        private BitmapFrameEncode() : base(true)
        {
        } 

        #endregion 
 
        #region IUriContext
 
        /// 
        /// Provides the base uri of the current context.
        /// 
        public override Uri BaseUri 
        {
            get 
            { 
                ReadPreamble();
                return null; 
            }
            set
            {
                WritePreamble(); 
            }
        } 
 
        #endregion
 
        #region Public Properties

        /// 
        /// Accesses the Thumbnail property for this BitmapFrameEncode 
        /// 
        public override BitmapSource Thumbnail 
        { 
            get
            { 
                ReadPreamble();
                return _thumbnail;
            }
        } 

        ///  
        /// Accesses the Metadata property for this BitmapFrameEncode 
        /// 
        public override ImageMetadata Metadata 
        {
            get
            {
                ReadPreamble(); 
                return InternalMetadata;
            } 
        } 

        ///  
        /// Accesses the Decoder property for this BitmapFrameEncode
        /// 
        public override BitmapDecoder Decoder
        { 
            get
            { 
                ReadPreamble(); 
                return null;
            } 
        }

        /// 
        /// Accesses the ColorContext property for this BitmapFrameEncode 
        /// 
        public override ReadOnlyCollection ColorContexts 
        { 
            get
            { 
                ReadPreamble();
                return _readOnlycolorContexts;
            }
        } 

 
        #endregion 

        #region Public Methods 

        /// 
        /// Create an in-place bitmap metadata writer.
        ///  
        public override InPlaceBitmapMetadataWriter CreateInPlaceBitmapMetadataWriter()
        { 
            ReadPreamble(); 
            return null;
        } 

        #endregion

        #region Freezable 
        /// 
        /// Implementation of Freezable.CreateInstanceCore. 
        ///  
        /// The new Freezable.
        protected override Freezable CreateInstanceCore() 
        {
            return new BitmapFrameEncode();
        }
 
        /// 
        /// Copy the fields not covered by DPs.  This is used by 
        /// CloneCore(), CloneCurrentValueCore(), GetAsFrozenCore() and 
        /// GetCurrentValueAsFrozenCore().
        ///  
        private void CopyCommon(BitmapFrameEncode sourceBitmapFrameEncode)
        {
            _bitmapInit.BeginInit();
 
            Debug.Assert(sourceBitmapFrameEncode._source != null);
            _source = sourceBitmapFrameEncode._source; 
            _frameSource = sourceBitmapFrameEncode._frameSource; 
            _thumbnail = sourceBitmapFrameEncode._thumbnail;
            _readOnlycolorContexts = sourceBitmapFrameEncode.ColorContexts; 

            if (sourceBitmapFrameEncode.InternalMetadata != null)
            {
                InternalMetadata = sourceBitmapFrameEncode.InternalMetadata.Clone(); 
            }
 
            _bitmapInit.EndInit(); 
        }
 
        /// 
        /// Implementation of Freezable.CloneCore.
        /// 
        protected override void CloneCore(Freezable sourceFreezable) 
        {
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable; 
            base.CloneCore(sourceFreezable); 

            CopyCommon(sourceBitmapFrameEncode); 
        }

        /// 
        /// Implementation of Freezable.CloneCurrentValueCore. 
        /// 
        protected override void CloneCurrentValueCore(Freezable sourceFreezable) 
        { 
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable;
            base.CloneCurrentValueCore(sourceFreezable); 

            CopyCommon(sourceBitmapFrameEncode);
        }
 

        ///  
        /// Implementation of Freezable.GetAsFrozenCore. 
        /// 
        protected override void GetAsFrozenCore(Freezable sourceFreezable) 
        {
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable;
            base.GetAsFrozenCore(sourceFreezable);
 
            CopyCommon(sourceBitmapFrameEncode);
        } 
 

        ///  
        /// Implementation of Freezable.GetCurrentValueAsFrozenCore.
        /// 
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        { 
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable;
            base.GetCurrentValueAsFrozenCore(sourceFreezable); 
 
            CopyCommon(sourceBitmapFrameEncode);
        } 


        #endregion
 
        #region Internal Properties / Methods
 
        ///  
        /// Create the unmanaged resources
        ///  
        /// 
        /// Critical - access critical resources
        /// TreatAsSafe - All inputs verified
        ///  
        [SecurityCritical, SecurityTreatAsSafe]
        internal override void FinalizeCreation() 
        { 
            CreationCompleted = true;
            UpdateCachedSettings(); 
        }

        /// 
        /// Internally stores the bitmap metadata 
        /// 
        ///  
        /// Critical - Access critical resource (_metadata) 
        /// TreatAsSafe - site of origin is verified if possible.
        ///  
        internal override BitmapMetadata InternalMetadata
        {
            [SecurityCritical, SecurityTreatAsSafe]
            get 
            {
                // Demand Site Of Origin on the URI before usage of metadata. 
                CheckIfSiteOfOrigin(); 

                return _metadata; 
            }
            [SecurityCritical, SecurityTreatAsSafe]
            set
            { 
                // Demand Site Of Origin on the URI before usage of metadata.
                CheckIfSiteOfOrigin(); 
 
                _metadata = value;
            } 
        }

        #endregion
 
        #region Internal Abstract
 
        /// Need to implement this to derive from the "sealed" object 
        internal override void SealObject()
        { 
            throw new NotImplementedException();
        }

        #endregion 

        #region Data Members 
 
        /// Source for this Frame
        private BitmapSource _source; 

        #endregion
    }
 
    #endregion // BitmapFrameEncode
} 
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------ 
//  Microsoft Avalon
//  Copyright (c) Microsoft Corporation
//
//  File: BitmapFrameEncode.cs 
//
//----------------------------------------------------------------------------- 
 
using System;
using System.Collections; 
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection; 
using MS.Internal;
using System.Diagnostics; 
using System.Windows.Media; 
using System.Globalization;
using System.Security; 
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Windows.Media.Animation;
using System.Windows.Media.Composition; 
using System.Windows.Media.Imaging;
using MS.Win32; 
 
namespace System.Windows.Media.Imaging
{ 
    #region BitmapFrameEncode

    /// 
    /// BitmapFrameEncode abstract class 
    /// 
    internal sealed class BitmapFrameEncode : BitmapFrame 
    { 

        #region Constructors 

        /// 
        /// Internal constructor
        ///  
        /// 
        /// SecurityCritical: Accesses unmanaged resources (_wicSource) 
        /// SecurityTreatAsSafe: Inputs are verified and _wicSource and the get is Critical 
        /// 
        [SecurityCritical, SecurityTreatAsSafe] 
        internal BitmapFrameEncode(
            BitmapSource source,
            BitmapSource thumbnail,
            BitmapMetadata metadata, 
            ReadOnlyCollection colorContexts
            ) 
            : base(true) 
        {
            _bitmapInit.BeginInit(); 

            Debug.Assert(source != null);
            _source = source;
            WicSourceHandle = _source.WicSourceHandle; 
            IsSourceCached = _source.IsSourceCached;
            _isColorCorrected = _source._isColorCorrected; 
            _thumbnail = thumbnail; 
            _readOnlycolorContexts = colorContexts;
            InternalMetadata = metadata; 
            _syncObject = source.SyncObject;
            _bitmapInit.EndInit();

            FinalizeCreation(); 
        }
 
        ///  
        /// Do not allow construction
        /// This will be called for cloning 
        /// 
        private BitmapFrameEncode() : base(true)
        {
        } 

        #endregion 
 
        #region IUriContext
 
        /// 
        /// Provides the base uri of the current context.
        /// 
        public override Uri BaseUri 
        {
            get 
            { 
                ReadPreamble();
                return null; 
            }
            set
            {
                WritePreamble(); 
            }
        } 
 
        #endregion
 
        #region Public Properties

        /// 
        /// Accesses the Thumbnail property for this BitmapFrameEncode 
        /// 
        public override BitmapSource Thumbnail 
        { 
            get
            { 
                ReadPreamble();
                return _thumbnail;
            }
        } 

        ///  
        /// Accesses the Metadata property for this BitmapFrameEncode 
        /// 
        public override ImageMetadata Metadata 
        {
            get
            {
                ReadPreamble(); 
                return InternalMetadata;
            } 
        } 

        ///  
        /// Accesses the Decoder property for this BitmapFrameEncode
        /// 
        public override BitmapDecoder Decoder
        { 
            get
            { 
                ReadPreamble(); 
                return null;
            } 
        }

        /// 
        /// Accesses the ColorContext property for this BitmapFrameEncode 
        /// 
        public override ReadOnlyCollection ColorContexts 
        { 
            get
            { 
                ReadPreamble();
                return _readOnlycolorContexts;
            }
        } 

 
        #endregion 

        #region Public Methods 

        /// 
        /// Create an in-place bitmap metadata writer.
        ///  
        public override InPlaceBitmapMetadataWriter CreateInPlaceBitmapMetadataWriter()
        { 
            ReadPreamble(); 
            return null;
        } 

        #endregion

        #region Freezable 
        /// 
        /// Implementation of Freezable.CreateInstanceCore. 
        ///  
        /// The new Freezable.
        protected override Freezable CreateInstanceCore() 
        {
            return new BitmapFrameEncode();
        }
 
        /// 
        /// Copy the fields not covered by DPs.  This is used by 
        /// CloneCore(), CloneCurrentValueCore(), GetAsFrozenCore() and 
        /// GetCurrentValueAsFrozenCore().
        ///  
        private void CopyCommon(BitmapFrameEncode sourceBitmapFrameEncode)
        {
            _bitmapInit.BeginInit();
 
            Debug.Assert(sourceBitmapFrameEncode._source != null);
            _source = sourceBitmapFrameEncode._source; 
            _frameSource = sourceBitmapFrameEncode._frameSource; 
            _thumbnail = sourceBitmapFrameEncode._thumbnail;
            _readOnlycolorContexts = sourceBitmapFrameEncode.ColorContexts; 

            if (sourceBitmapFrameEncode.InternalMetadata != null)
            {
                InternalMetadata = sourceBitmapFrameEncode.InternalMetadata.Clone(); 
            }
 
            _bitmapInit.EndInit(); 
        }
 
        /// 
        /// Implementation of Freezable.CloneCore.
        /// 
        protected override void CloneCore(Freezable sourceFreezable) 
        {
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable; 
            base.CloneCore(sourceFreezable); 

            CopyCommon(sourceBitmapFrameEncode); 
        }

        /// 
        /// Implementation of Freezable.CloneCurrentValueCore. 
        /// 
        protected override void CloneCurrentValueCore(Freezable sourceFreezable) 
        { 
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable;
            base.CloneCurrentValueCore(sourceFreezable); 

            CopyCommon(sourceBitmapFrameEncode);
        }
 

        ///  
        /// Implementation of Freezable.GetAsFrozenCore. 
        /// 
        protected override void GetAsFrozenCore(Freezable sourceFreezable) 
        {
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable;
            base.GetAsFrozenCore(sourceFreezable);
 
            CopyCommon(sourceBitmapFrameEncode);
        } 
 

        ///  
        /// Implementation of Freezable.GetCurrentValueAsFrozenCore.
        /// 
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        { 
            BitmapFrameEncode sourceBitmapFrameEncode = (BitmapFrameEncode)sourceFreezable;
            base.GetCurrentValueAsFrozenCore(sourceFreezable); 
 
            CopyCommon(sourceBitmapFrameEncode);
        } 


        #endregion
 
        #region Internal Properties / Methods
 
        ///  
        /// Create the unmanaged resources
        ///  
        /// 
        /// Critical - access critical resources
        /// TreatAsSafe - All inputs verified
        ///  
        [SecurityCritical, SecurityTreatAsSafe]
        internal override void FinalizeCreation() 
        { 
            CreationCompleted = true;
            UpdateCachedSettings(); 
        }

        /// 
        /// Internally stores the bitmap metadata 
        /// 
        ///  
        /// Critical - Access critical resource (_metadata) 
        /// TreatAsSafe - site of origin is verified if possible.
        ///  
        internal override BitmapMetadata InternalMetadata
        {
            [SecurityCritical, SecurityTreatAsSafe]
            get 
            {
                // Demand Site Of Origin on the URI before usage of metadata. 
                CheckIfSiteOfOrigin(); 

                return _metadata; 
            }
            [SecurityCritical, SecurityTreatAsSafe]
            set
            { 
                // Demand Site Of Origin on the URI before usage of metadata.
                CheckIfSiteOfOrigin(); 
 
                _metadata = value;
            } 
        }

        #endregion
 
        #region Internal Abstract
 
        /// Need to implement this to derive from the "sealed" object 
        internal override void SealObject()
        { 
            throw new NotImplementedException();
        }

        #endregion 

        #region Data Members 
 
        /// Source for this Frame
        private BitmapSource _source; 

        #endregion
    }
 
    #endregion // BitmapFrameEncode
} 
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK