Code:
                         / Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / ColorConvertedBitmapExtension.cs / 1 / ColorConvertedBitmapExtension.cs
                        
                        
                            /****************************************************************************\ 
*
* File: ColorConvertedBitmapExtension.cs
*
*  Class for Xaml markup extension for static resource references. 
*
* Copyright (C) 2004 by Microsoft Corporation.  All rights reserved. 
* 
\***************************************************************************/
 
using System;
using System.IO;
using System.Collections;
using System.Diagnostics; 
using System.Windows;
using System.Windows.Documents; 
using System.Windows.Markup; 
using System.Windows.Media;
using System.Windows.Media.Imaging; 
using System.Reflection;
using MS.Internal;
namespace System.Windows 
{
    ///  
    ///  Class for Xaml markup extension for ColorConvertedBitmap with non-embedded profile. 
    ///  
    [MarkupExtensionReturnType(typeof(ColorConvertedBitmap))] 
    public class ColorConvertedBitmapExtension : MarkupExtension
    {
        /// 
        ///  Constructor that takes no parameters 
        ///  
        public ColorConvertedBitmapExtension() 
        { 
        }
 
        /// 
        ///  Constructor that takes the markup for a "{ColorConvertedBitmap image source.icc destination.icc}"
        ///  
        public ColorConvertedBitmapExtension( 
            object image)
        { 
            if (image == null) 
            {
                throw new ArgumentNullException("image"); 
            }
            string[] tokens = ((string)image).Split(new char[] { ' ' });
 
            foreach (string str in tokens)
            { 
                if (str.Length > 0) 
                {
                    if (_image == null) 
                    {
                        _image = str;
                    }
                    else if (_sourceProfile == null) 
                    {
                        _sourceProfile = str; 
                    } 
                    else if (_destinationProfile == null)
                    { 
                        _destinationProfile = str;
                    }
                    else
                    { 
                        throw new InvalidOperationException(SR.Get(SRID.ColorConvertedBitmapExtensionSyntax));
                    } 
                } 
            }
        } 
        /// 
        ///  Return an object that should be set on the targetObject's targetProperty
        ///  for this markup extension.  For ColorConvertedBitmapExtension, this is the object found in 
        ///  a resource dictionary in the current parent chain that is keyed by ResourceKey
        ///   
        ///  
        ///  The object to set on this property.
        ///   
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (_image == null)
            { 
                throw new InvalidOperationException(SR.Get(SRID.ColorConvertedBitmapExtensionNoSourceImage));
            } 
            if (_sourceProfile == null) 
            {
                throw new InvalidOperationException(SR.Get(SRID.ColorConvertedBitmapExtensionNoSourceProfile)); 
            }
            // Save away the BaseUri.
            IUriContext uriContext = serviceProvider.GetService(typeof(IUriContext)) as IUriContext; 
            if( uriContext == null )
            { 
                throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IUriContext" )); 
            }
            _baseUri = uriContext.BaseUri; 
            Uri imageUri = GetResolvedUri(_image);
            Uri sourceProfileUri = GetResolvedUri(_sourceProfile); 
            Uri destinationProfileUri = GetResolvedUri(_destinationProfile);
 
            ColorContext sourceContext = new ColorContext(sourceProfileUri); 
            ColorContext destinationContext = destinationProfileUri != null ?
                                                new ColorContext(destinationProfileUri) : 
                                                new ColorContext(PixelFormats.Default);
            BitmapDecoder decoder = BitmapDecoder.Create(
                                                                imageUri, 
                                                                BitmapCreateOptions.IgnoreColorProfile | BitmapCreateOptions.IgnoreImageCache,
                                                                BitmapCacheOption.None 
                                                                ); 
            BitmapSource bitmap = decoder.Frames[0]; 
            FormatConvertedBitmap formatConverted = new FormatConvertedBitmap(bitmap, PixelFormats.Bgra32, null, 0.0);
            object result = formatConverted;
 
            try
            { 
                ColorConvertedBitmap colorConverted = new ColorConvertedBitmap(formatConverted, sourceContext, destinationContext, PixelFormats.Bgra32); 
                result= colorConverted;
            } 
            catch (FileFormatException)
            {   // Gracefully ignore non-matching profile
                // If the file contains a bad color context, we catch the exception here
                // since color transform isn't possible 
                // with the given color context.
            } 
 
            return result;
        } 
        private Uri GetResolvedUri(string uri)
        {
            if (uri == null) 
            {
                return null; 
            } 
            return new Uri(_baseUri,uri); 
        }
        string _image;
        string _sourceProfile; 
        Uri _baseUri;
        string _destinationProfile; 
    } 
}
 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/****************************************************************************\ 
*
* File: ColorConvertedBitmapExtension.cs
*
*  Class for Xaml markup extension for static resource references. 
*
* Copyright (C) 2004 by Microsoft Corporation.  All rights reserved. 
* 
\***************************************************************************/
 
using System;
using System.IO;
using System.Collections;
using System.Diagnostics; 
using System.Windows;
using System.Windows.Documents; 
using System.Windows.Markup; 
using System.Windows.Media;
using System.Windows.Media.Imaging; 
using System.Reflection;
using MS.Internal;
namespace System.Windows 
{
    ///  
    ///  Class for Xaml markup extension for ColorConvertedBitmap with non-embedded profile. 
    ///  
    [MarkupExtensionReturnType(typeof(ColorConvertedBitmap))] 
    public class ColorConvertedBitmapExtension : MarkupExtension
    {
        /// 
        ///  Constructor that takes no parameters 
        ///  
        public ColorConvertedBitmapExtension() 
        { 
        }
 
        /// 
        ///  Constructor that takes the markup for a "{ColorConvertedBitmap image source.icc destination.icc}"
        ///  
        public ColorConvertedBitmapExtension( 
            object image)
        { 
            if (image == null) 
            {
                throw new ArgumentNullException("image"); 
            }
            string[] tokens = ((string)image).Split(new char[] { ' ' });
 
            foreach (string str in tokens)
            { 
                if (str.Length > 0) 
                {
                    if (_image == null) 
                    {
                        _image = str;
                    }
                    else if (_sourceProfile == null) 
                    {
                        _sourceProfile = str; 
                    } 
                    else if (_destinationProfile == null)
                    { 
                        _destinationProfile = str;
                    }
                    else
                    { 
                        throw new InvalidOperationException(SR.Get(SRID.ColorConvertedBitmapExtensionSyntax));
                    } 
                } 
            }
        } 
        /// 
        ///  Return an object that should be set on the targetObject's targetProperty
        ///  for this markup extension.  For ColorConvertedBitmapExtension, this is the object found in 
        ///  a resource dictionary in the current parent chain that is keyed by ResourceKey
        ///   
        ///  
        ///  The object to set on this property.
        ///   
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (_image == null)
            { 
                throw new InvalidOperationException(SR.Get(SRID.ColorConvertedBitmapExtensionNoSourceImage));
            } 
            if (_sourceProfile == null) 
            {
                throw new InvalidOperationException(SR.Get(SRID.ColorConvertedBitmapExtensionNoSourceProfile)); 
            }
            // Save away the BaseUri.
            IUriContext uriContext = serviceProvider.GetService(typeof(IUriContext)) as IUriContext; 
            if( uriContext == null )
            { 
                throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IUriContext" )); 
            }
            _baseUri = uriContext.BaseUri; 
            Uri imageUri = GetResolvedUri(_image);
            Uri sourceProfileUri = GetResolvedUri(_sourceProfile); 
            Uri destinationProfileUri = GetResolvedUri(_destinationProfile);
 
            ColorContext sourceContext = new ColorContext(sourceProfileUri); 
            ColorContext destinationContext = destinationProfileUri != null ?
                                                new ColorContext(destinationProfileUri) : 
                                                new ColorContext(PixelFormats.Default);
            BitmapDecoder decoder = BitmapDecoder.Create(
                                                                imageUri, 
                                                                BitmapCreateOptions.IgnoreColorProfile | BitmapCreateOptions.IgnoreImageCache,
                                                                BitmapCacheOption.None 
                                                                ); 
            BitmapSource bitmap = decoder.Frames[0]; 
            FormatConvertedBitmap formatConverted = new FormatConvertedBitmap(bitmap, PixelFormats.Bgra32, null, 0.0);
            object result = formatConverted;
 
            try
            { 
                ColorConvertedBitmap colorConverted = new ColorConvertedBitmap(formatConverted, sourceContext, destinationContext, PixelFormats.Bgra32); 
                result= colorConverted;
            } 
            catch (FileFormatException)
            {   // Gracefully ignore non-matching profile
                // If the file contains a bad color context, we catch the exception here
                // since color transform isn't possible 
                // with the given color context.
            } 
 
            return result;
        } 
        private Uri GetResolvedUri(string uri)
        {
            if (uri == null) 
            {
                return null; 
            } 
            return new Uri(_baseUri,uri); 
        }
        string _image;
        string _sourceProfile; 
        Uri _baseUri;
        string _destinationProfile; 
    } 
}
 
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        
                        
                        
                        
                    Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TripleDES.cs
- PreProcessInputEventArgs.cs
- MobileCategoryAttribute.cs
- ConnectionConsumerAttribute.cs
- ActivityCodeGenerator.cs
- ObjectSecurity.cs
- ScalarRestriction.cs
- ExecutionEngineException.cs
- BypassElement.cs
- DataObjectEventArgs.cs
- dtdvalidator.cs
- HashHelpers.cs
- SafeBitVector32.cs
- _BaseOverlappedAsyncResult.cs
- XmlSchemaFacet.cs
- StringUtil.cs
- InputScope.cs
- WebBrowserPermission.cs
- ApplicationInfo.cs
- DesignerRegionCollection.cs
- infer.cs
- XmlEncodedRawTextWriter.cs
- ValidatorCompatibilityHelper.cs
- RawStylusSystemGestureInputReport.cs
- ViewGenerator.cs
- XmlComplianceUtil.cs
- AssemblyAttributesGoHere.cs
- JumpTask.cs
- DataGridViewCheckBoxCell.cs
- CaseInsensitiveHashCodeProvider.cs
- FlowLayout.cs
- WorkflowQueueInfo.cs
- ClientSponsor.cs
- DrawingAttributesDefaultValueFactory.cs
- WebPartCollection.cs
- NavigationProgressEventArgs.cs
- IntAverageAggregationOperator.cs
- SoapAttributeAttribute.cs
- HexParser.cs
- TailCallAnalyzer.cs
- RangeValidator.cs
- PersonalizationProvider.cs
- panel.cs
- MarkupCompilePass2.cs
- BaseParagraph.cs
- SessionStateContainer.cs
- DefaultAsyncDataDispatcher.cs
- DataGridLinkButton.cs
- ManipulationBoundaryFeedbackEventArgs.cs
- SecureStringHasher.cs
- UDPClient.cs
- ClientType.cs
- FixedSOMElement.cs
- ContentWrapperAttribute.cs
- RightsManagementResourceHelper.cs
- DSASignatureDeformatter.cs
- TabControl.cs
- InternalConfigHost.cs
- SimpleBitVector32.cs
- IteratorFilter.cs
- Matrix3DStack.cs
- ConnectionPoolManager.cs
- ThreadExceptionEvent.cs
- CodeTypeMember.cs
- DependencyPropertyConverter.cs
- ScriptResourceInfo.cs
- ReflectionServiceProvider.cs
- IndentTextWriter.cs
- EntityCommandExecutionException.cs
- EncryptedXml.cs
- SelectedDatesCollection.cs
- BindingSource.cs
- TextContainer.cs
- TextContainerChangedEventArgs.cs
- LongValidatorAttribute.cs
- SerTrace.cs
- QilParameter.cs
- AssemblyName.cs
- MSG.cs
- ClientProxyGenerator.cs
- TextureBrush.cs
- AnnotationStore.cs
- SymmetricSecurityProtocol.cs
- TraceContextEventArgs.cs
- XPathAncestorIterator.cs
- FixedBufferAttribute.cs
- StreamReader.cs
- EpmSourcePathSegment.cs
- BrushMappingModeValidation.cs
- ConditionalExpression.cs
- DataGridViewButtonColumn.cs
- SrgsElementList.cs
- Int32EqualityComparer.cs
- WebGetAttribute.cs
- IgnoreDataMemberAttribute.cs
- XmlDataSourceNodeDescriptor.cs
- FormsAuthentication.cs
- TimeoutTimer.cs
- RadioButtonList.cs
- DataGridViewColumnConverter.cs