Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / Serialization / XpsImageSerializationService.cs / 1 / XpsImageSerializationService.cs
/*++ Copyright (C) 2004 - 2005 Microsoft Corporation All rights reserved. Module Name: XpsImageSerializationService.cs Abstract: This file implements the XpsImageSerializationService used by the Xps Serialization APIs for serializing images to a Xps package. Author: [....] ([....]) 1-December-2004 Revision History: 07/12/2005: [....]: Reach -> Xps --*/ using System; using System.IO; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Security; using System.Security.Permissions; using System.Windows.Xps.Packaging; using MS.Internal; namespace System.Windows.Xps.Serialization { ////// This class implements a support service for serialization /// of BitmapSource instances to a Xps package. /// internal class XpsImageSerializationService { #region Public methods ////// This method retrieves the BitmapEncoder to be used for /// serialization based on the specified BitmapSource. /// /// /// A reference to a BitmapSource that will be encoded. /// ////// Returns a reference to a new BitmapEncoder. /// ////// Critical - 1) Asserts to access the registry. May return path information which /// could disclose windows directory (ie. c:\windows\media\sound.wav) /// /// [SecurityCritical] public BitmapEncoder GetEncoder( BitmapSource bitmapSource ) { BitmapEncoder encoder = null; if (bitmapSource is BitmapFrame) { // // This code gets the encoder based on the decoder that was // used for this specific BitmapSource. // BitmapFrame bitmapImage = bitmapSource as BitmapFrame; BitmapCodecInfo codecInfo = null; if (bitmapImage != null && bitmapImage.Decoder != null) codecInfo = bitmapImage.Decoder.CodecInfo; if (codecInfo != null) { (new RegistryPermission(PermissionState.Unrestricted)).Assert(); try { encoder = BitmapEncoder.Create(codecInfo.ContainerFormat); } finally { RegistryPermission.RevertAssert(); } // Avoid GIF encoder which does not save transparency well if ( !( encoder is JpegBitmapEncoder || encoder is PngBitmapEncoder || encoder is TiffBitmapEncoder || encoder is WmpBitmapEncoder) ) { encoder = null; } } } // // The code above assumes that the BitmapSource is actually // a BitmapImage. If it is not then we assume Png and use // that encoder. // if (encoder == null) { if (Microsoft.Internal.AlphaFlattener.Utility.NeedPremultiplyAlpha(bitmapSource)) { encoder = new WmpBitmapEncoder(); } else { encoder = new PngBitmapEncoder(); } } return encoder; } ////// This method determines if a bitmap is of a supported /// Xps Mime type /// /// /// A reference to a BitmapSource to be tested. /// ////// Returns true if the bitmapSource is of supported mimetype /// ////// Critical - 1) Asserts to access the registry. May return path information which /// could disclose windows directory (ie. c:\windows\media\sound.wav) /// /// [SecurityCritical] public bool IsSupportedMimeType( BitmapSource bitmapSource ) { BitmapCodecInfo codecInfo = null; string imageMimeType = ""; if (bitmapSource is BitmapFrame) { // // This code gets the encoder based on the decoder that was // used for this specific BitmapSource. // BitmapFrame bitmapFrame = bitmapSource as BitmapFrame; if (bitmapFrame != null && bitmapFrame.Decoder != null) { codecInfo = bitmapFrame.Decoder.CodecInfo; } } if (codecInfo != null) { (new RegistryPermission(PermissionState.Unrestricted)).Assert(); try { imageMimeType = codecInfo.MimeTypes; } finally { RegistryPermission.RevertAssert(); } } int start = 0; int comma = imageMimeType.IndexOf(',', start); bool foundType = false; // // Test all strings before commas // if( comma != -1 ) { while (comma != -1 && !foundType) { string subString = imageMimeType.Substring(start, comma); foundType = XpsManager.SupportedImageType( new ContentType(subString) ); start = comma+1; comma = imageMimeType.IndexOf(',', start); } } // // If we still have not found a supported type // Test the remainder of the string // if( !foundType ) { foundType = XpsManager.SupportedImageType( new ContentType(imageMimeType.Substring(start)) ); } return foundType; } ////// This method verifies whether a given BitmapSource /// is serializable by this service. /// /// /// A reference to a BitmapSource to be checked. /// ////// A boolean value specifing serializability. /// public bool VerifyImageSourceSerializability( BitmapSource bitmapSource ) { throw new NotImplementedException(); } ////// This method serializes a given BitmapSource to a /// stream and returns a reference to the stream. /// /// /// A reference to a BitmapSource to be serialized. /// ////// A reference to a Stream where BitmapSource was serialized. /// public Stream SerializeToStream( BitmapSource bitmapSource ) { throw new NotImplementedException(); } #endregion Public methods } } // 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
- Mapping.cs
- ValidationError.cs
- BaseProcessor.cs
- Binding.cs
- TdsParserSafeHandles.cs
- XmlNullResolver.cs
- HtmlValidationSummaryAdapter.cs
- FakeModelItemImpl.cs
- DynamicPropertyHolder.cs
- RotationValidation.cs
- _ScatterGatherBuffers.cs
- BuildResult.cs
- DoubleUtil.cs
- OnOperation.cs
- RowCache.cs
- TypeInitializationException.cs
- SettingsAttributeDictionary.cs
- WmlFormAdapter.cs
- DesignerValidatorAdapter.cs
- ButtonRenderer.cs
- StringAnimationUsingKeyFrames.cs
- HotSpotCollection.cs
- XmlFormatExtensionPrefixAttribute.cs
- ResourcePool.cs
- FamilyMap.cs
- SchemaNotation.cs
- SchemaEntity.cs
- Axis.cs
- InvalidContentTypeException.cs
- VersionedStreamOwner.cs
- ItemsControlAutomationPeer.cs
- FormViewRow.cs
- StoreAnnotationsMap.cs
- SrgsElementFactoryCompiler.cs
- ParagraphVisual.cs
- FixedSOMTableCell.cs
- XmlSchemaParticle.cs
- DebugView.cs
- TableRowCollection.cs
- ChainOfDependencies.cs
- DecimalAverageAggregationOperator.cs
- Input.cs
- WebCategoryAttribute.cs
- XdrBuilder.cs
- LinqDataSourceHelper.cs
- UIElement3D.cs
- FrameworkContentElement.cs
- TargetFrameworkUtil.cs
- HttpModuleCollection.cs
- ListViewTableCell.cs
- ElapsedEventArgs.cs
- HandledEventArgs.cs
- BindStream.cs
- StyleSheetRefUrlEditor.cs
- WindowPattern.cs
- RegexGroup.cs
- _KerberosClient.cs
- ResourceSet.cs
- CodeBinaryOperatorExpression.cs
- VersionedStreamOwner.cs
- RadioButtonRenderer.cs
- MessageQueuePermission.cs
- TemplateLookupAction.cs
- SafeThemeHandle.cs
- SeekStoryboard.cs
- IPAddress.cs
- MultiAsyncResult.cs
- ProtocolsSection.cs
- _Rfc2616CacheValidators.cs
- DataGridViewComboBoxCell.cs
- SqlTriggerAttribute.cs
- CombinedGeometry.cs
- DesigntimeLicenseContextSerializer.cs
- XmlReflectionMember.cs
- AuthorizationRule.cs
- ProcessProtocolHandler.cs
- StreamMarshaler.cs
- ToolStripItemEventArgs.cs
- ITextView.cs
- RightsManagementPermission.cs
- DllNotFoundException.cs
- DependencyObjectPropertyDescriptor.cs
- TileBrush.cs
- ObjectDataSourceMethodEventArgs.cs
- DependentList.cs
- ViewRendering.cs
- ColorIndependentAnimationStorage.cs
- DesignerAttribute.cs
- TableItemStyle.cs
- rsa.cs
- LambdaCompiler.Expressions.cs
- DesignerRegionCollection.cs
- FileDialogCustomPlace.cs
- SqlBuilder.cs
- SerializerWriterEventHandlers.cs
- _IPv6Address.cs
- MenuItemCollection.cs
- Int32RectValueSerializer.cs
- XmlValidatingReader.cs
- XmlSortKeyAccumulator.cs