Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Core / System / Windows / Media / Effects / BitmapEffectvisualstate.cs / 1 / BitmapEffectvisualstate.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2005 // // File: BitmapEffectVisualState.cs //----------------------------------------------------------------------------- using System; using System.Windows.Threading; using MS.Win32; using System.Security; using System.Security.Permissions; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Composition; using System.Windows.Media.Imaging; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using MS.Internal; using System.Resources; using MS.Utility; using System.Runtime.InteropServices; using MS.Internal.PresentationCore; using SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace System.Windows.Media.Effects { ////// This class is used to realize the content of the /// visual if a bitmap effect is applied to it /// internal class BitmapEffectContent : IRealizationContextClient { Visual _visual; List_channels; public BitmapEffectContent(Visual v, RealizationContext ctx) { _visual = v; _channels = ctx.Channels; } public void ExecuteRealizationsUpdate() { Visual.BitmapEffectStateField.GetValue(_visual).RenderBitmapEffect(_visual, _channels); } } /// /// /// internal class BitmapEffectVisualState : BitmapEffectState { public BitmapEffectVisualState() { } public BitmapEffectDrawing BitmapEffectDrawing { get { if (_bitmapEffectDrawing == null) { _bitmapEffectDrawing = new BitmapEffectDrawing(); } return _bitmapEffectDrawing; } set { _bitmapEffectDrawing = null; } } ////// Remove the content from the composition node /// /// /// internal void FreeContent(Visual visual, DUCE.Channel channel) { SetContent(null, visual, channel); _bitmapEffectDrawing = null; } ////// This sets the content of the visual if there is a /// bitmap effect applied to it /// /// drawing content /// The visual /// The channel internal void SetContent(IDrawingContent content, Visual visual, DUCE.Channel channel) { DUCE.ResourceHandle visualHandle = ((DUCE.IResource)visual).GetHandle(channel); if (content != null) { content.AddRefOnChannel(channel); DUCE.CompositionNode.SetContent( visualHandle, content.GetHandle(channel), channel); // it is ok to release here, because the unmanaged code // holds a reference to the content and will release it // when the parent object is released or the content // is reset to null content.ReleaseOnChannel(channel); } else { Debug.Assert(visual.IsOnChannel(channel)); DUCE.CompositionNode.SetContent( visualHandle, DUCE.ResourceHandle.Null, channel); } } ////// This methods renders the visual to a bitmap, then applies /// the effect to the rendered bitmap, and sets the content /// of the visual to be the resulting bitmap /// /// The visual to apply the effect to /// The current channels internal void RenderBitmapEffect(Visual visual, Listchannels) { if (_bitmapEffect == null) throw new InvalidOperationException(SR.Get(SRID.Visual_No_Effect, null)); Debug.Assert(channels.Count >= 1); Debug.Assert(channels[0].Channel != null); BitmapEffectDrawing.UpdateTransformAndDrawingLists(true); bool effectRendered = false; int drawingsCount = BitmapEffectDrawing.Drawings.Count; for (int iTransform = BitmapEffectDrawing.WorldTransforms.Count - 1; iTransform >= drawingsCount; iTransform--) { Matrix finalTransform = BitmapEffectDrawing.WorldTransforms[iTransform].Value; BitmapSource outputImage = GetEffectOutput(visual, ref _renderBitmap, finalTransform, BitmapEffectDrawing.WindowClip, out finalTransform); if (outputImage != null) { // if there was no group for that transform create one // and update it, otherwise we don't need to do anything it // NOTE: this is ok to update here since it is not // connected to the visual tree DrawingGroup effectGroup = new DrawingGroup(); effectGroup.Children.Add( new ImageDrawing(outputImage, new Rect(0, 0, outputImage.Width, outputImage.Height))); effectGroup.Transform = new MatrixTransform(finalTransform); BitmapEffectDrawing.Drawings.Insert(drawingsCount, effectGroup); effectRendered = true; } else { BitmapEffectDrawing.WorldTransforms.RemoveAt(iTransform); } } if (BitmapEffectDrawing.Drawings.Count > 0 && effectRendered == true) { foreach(DUCE.ChannelSet channelSet in channels) { SetContent(BitmapEffectDrawing, visual, channelSet.Channel); } } // reset the dirty flag // we have already rendered the visual and applied the effect foreach (DUCE.ChannelSet channelSet in channels) { visual.SetFlags(channelSet.Channel, false, VisualProxyFlags.IsBitmapEffectDirty); } BitmapEffectDrawing.ScheduleForUpdates = true; } #region Private Fields BitmapEffectDrawing _bitmapEffectDrawing; RenderTargetBitmap _renderBitmap; #endregion } } // 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
- Binding.cs
- TypeValidationEventArgs.cs
- Soap12ServerProtocol.cs
- WindowsFormsEditorServiceHelper.cs
- OleDbError.cs
- ValueExpressions.cs
- SoapSchemaImporter.cs
- Receive.cs
- ClickablePoint.cs
- BitConverter.cs
- DateTimeConverter.cs
- OleDbCommand.cs
- DataBoundControlHelper.cs
- FamilyMapCollection.cs
- RelationshipType.cs
- TabOrder.cs
- DropShadowEffect.cs
- BlurBitmapEffect.cs
- JoinCqlBlock.cs
- CompiledQueryCacheKey.cs
- precedingquery.cs
- PartialArray.cs
- _NestedSingleAsyncResult.cs
- Console.cs
- ActivityTypeDesigner.xaml.cs
- NullExtension.cs
- BookmarkInfo.cs
- ClientScriptManager.cs
- RedirectionProxy.cs
- DataSpaceManager.cs
- BatchParser.cs
- SimpleWebHandlerParser.cs
- PointConverter.cs
- AssertFilter.cs
- GenericXmlSecurityToken.cs
- ListBox.cs
- GridViewRowEventArgs.cs
- BadImageFormatException.cs
- Model3D.cs
- InternalSafeNativeMethods.cs
- ProxyFragment.cs
- BindingMemberInfo.cs
- _TransmitFileOverlappedAsyncResult.cs
- RealizationDrawingContextWalker.cs
- StylusPointDescription.cs
- SignatureToken.cs
- CompleteWizardStep.cs
- ConnectionInterfaceCollection.cs
- XPathSelectionIterator.cs
- TextTreeTextElementNode.cs
- FileSystemWatcher.cs
- ImageMapEventArgs.cs
- RenderingEventArgs.cs
- TypeElement.cs
- PropertyMapper.cs
- BitmapEffectInputConnector.cs
- SystemColors.cs
- PropertyPushdownHelper.cs
- X509Certificate.cs
- DependencyPropertyAttribute.cs
- Command.cs
- RectangleConverter.cs
- AvTraceDetails.cs
- DataGridHelper.cs
- DataBindingCollection.cs
- MissingMemberException.cs
- NamespaceCollection.cs
- ListControl.cs
- ByteKeyFrameCollection.cs
- ProfileInfo.cs
- PasswordBox.cs
- TextBoxBase.cs
- RuntimeHelpers.cs
- PackagePartCollection.cs
- ApplicationServiceHelper.cs
- ChangeInterceptorAttribute.cs
- ErrorWebPart.cs
- HtmlEmptyTagControlBuilder.cs
- PageThemeParser.cs
- XmlSchemaSimpleContentExtension.cs
- DrawTreeNodeEventArgs.cs
- ClientRolePrincipal.cs
- MenuItem.cs
- NullPackagingPolicy.cs
- TabControl.cs
- RowUpdatingEventArgs.cs
- Int32Animation.cs
- ColorContext.cs
- FileCodeGroup.cs
- Vars.cs
- itemelement.cs
- IISMapPath.cs
- UserThread.cs
- PostBackTrigger.cs
- CustomSignedXml.cs
- NumericUpDownAcceleration.cs
- Roles.cs
- Shape.cs
- ScaleTransform.cs
- GeneralTransform2DTo3D.cs