Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / InterOp / Imaging.cs / 1305600 / Imaging.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, All Rights Reserved. // // File: Imaging.cs // //----------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using MS.Internal; using System.Diagnostics; using System.Windows; using System.Windows.Media.Imaging; using Microsoft.Win32.SafeHandles; using MS.Internal.PresentationCore; // SecurityHelper using System.Windows.Interop; namespace System.Windows.Interop { ////// Managed/Unmanaged Interop for Imaging. /// public static class Imaging { ////// Construct an Bitmap from a HBITMAP. /// /// /// /// /// ////// Callers must have UnmanagedCode permission to call this API. /// ////// Critical - calls critical code, access unmanaged resources /// PublicOK - demands unmanaged code permission /// [SecurityCritical] unsafe public static BitmapSource CreateBitmapSourceFromHBitmap( IntPtr bitmap, IntPtr palette, Int32Rect sourceRect, BitmapSizeOptions sizeOptions) { SecurityHelper.DemandUnmanagedCode(); // CR: [....] (1681459) return CriticalCreateBitmapSourceFromHBitmap(bitmap, palette, sourceRect, sizeOptions, WICBitmapAlphaChannelOption.WICBitmapUseAlpha); } ////// Construct an Bitmap from a HBITMAP. /// /// /// /// /// /// ////// Critical - calls critical code, access unmanaged resources /// [SecurityCritical] unsafe internal static BitmapSource CriticalCreateBitmapSourceFromHBitmap( IntPtr bitmap, IntPtr palette, Int32Rect sourceRect, BitmapSizeOptions sizeOptions, WICBitmapAlphaChannelOption alphaOptions) { if (bitmap == IntPtr.Zero) { throw new ArgumentNullException("bitmap"); } return new InteropBitmap(bitmap, palette, sourceRect, sizeOptions, alphaOptions); // use the critical version } ////// Construct an Bitmap from a HICON. /// /// /// /// ////// Callers must have UnmanagedCode permission to call this API. /// ////// Critical - calls critical code, access unmanaged resources /// PublicOK - demands unmanaged code permission /// [SecurityCritical ] unsafe public static BitmapSource CreateBitmapSourceFromHIcon( IntPtr icon, Int32Rect sourceRect, BitmapSizeOptions sizeOptions) { SecurityHelper.DemandUnmanagedCode(); if (icon == IntPtr.Zero) { throw new ArgumentNullException("icon"); } return new InteropBitmap(icon, sourceRect, sizeOptions); } ////// Construct an Bitmap from a section handle. /// /// /// /// /// /// /// ////// Callers must have UnmanagedCode permission to call this API. /// ////// Critical - calls critical code, access unmanaged resources /// PublicOK - demands unmanaged code permission /// [SecurityCritical ] unsafe public static BitmapSource CreateBitmapSourceFromMemorySection( IntPtr section, int pixelWidth, int pixelHeight, Media.PixelFormat format, int stride, int offset) { SecurityHelper.DemandUnmanagedCode(); if (section == IntPtr.Zero) { throw new ArgumentNullException("section"); } return new InteropBitmap(section, pixelWidth, pixelHeight, format, stride, offset); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, All Rights Reserved. // // File: Imaging.cs // //----------------------------------------------------------------------------- using System; using System.Security; using System.Security.Permissions; using MS.Internal; using System.Diagnostics; using System.Windows; using System.Windows.Media.Imaging; using Microsoft.Win32.SafeHandles; using MS.Internal.PresentationCore; // SecurityHelper using System.Windows.Interop; namespace System.Windows.Interop { ////// Managed/Unmanaged Interop for Imaging. /// public static class Imaging { ////// Construct an Bitmap from a HBITMAP. /// /// /// /// /// ////// Callers must have UnmanagedCode permission to call this API. /// ////// Critical - calls critical code, access unmanaged resources /// PublicOK - demands unmanaged code permission /// [SecurityCritical] unsafe public static BitmapSource CreateBitmapSourceFromHBitmap( IntPtr bitmap, IntPtr palette, Int32Rect sourceRect, BitmapSizeOptions sizeOptions) { SecurityHelper.DemandUnmanagedCode(); // CR: [....] (1681459) return CriticalCreateBitmapSourceFromHBitmap(bitmap, palette, sourceRect, sizeOptions, WICBitmapAlphaChannelOption.WICBitmapUseAlpha); } ////// Construct an Bitmap from a HBITMAP. /// /// /// /// /// /// ////// Critical - calls critical code, access unmanaged resources /// [SecurityCritical] unsafe internal static BitmapSource CriticalCreateBitmapSourceFromHBitmap( IntPtr bitmap, IntPtr palette, Int32Rect sourceRect, BitmapSizeOptions sizeOptions, WICBitmapAlphaChannelOption alphaOptions) { if (bitmap == IntPtr.Zero) { throw new ArgumentNullException("bitmap"); } return new InteropBitmap(bitmap, palette, sourceRect, sizeOptions, alphaOptions); // use the critical version } ////// Construct an Bitmap from a HICON. /// /// /// /// ////// Callers must have UnmanagedCode permission to call this API. /// ////// Critical - calls critical code, access unmanaged resources /// PublicOK - demands unmanaged code permission /// [SecurityCritical ] unsafe public static BitmapSource CreateBitmapSourceFromHIcon( IntPtr icon, Int32Rect sourceRect, BitmapSizeOptions sizeOptions) { SecurityHelper.DemandUnmanagedCode(); if (icon == IntPtr.Zero) { throw new ArgumentNullException("icon"); } return new InteropBitmap(icon, sourceRect, sizeOptions); } ////// Construct an Bitmap from a section handle. /// /// /// /// /// /// /// ////// Callers must have UnmanagedCode permission to call this API. /// ////// Critical - calls critical code, access unmanaged resources /// PublicOK - demands unmanaged code permission /// [SecurityCritical ] unsafe public static BitmapSource CreateBitmapSourceFromMemorySection( IntPtr section, int pixelWidth, int pixelHeight, Media.PixelFormat format, int stride, int offset) { SecurityHelper.DemandUnmanagedCode(); if (section == IntPtr.Zero) { throw new ArgumentNullException("section"); } return new InteropBitmap(section, pixelWidth, pixelHeight, format, stride, offset); } } } // 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
- SolidColorBrush.cs
- DataKeyArray.cs
- IsolatedStorage.cs
- MetadataWorkspace.cs
- AccessibleObject.cs
- LogStore.cs
- BeginEvent.cs
- PropertyGeneratedEventArgs.cs
- XPathPatternBuilder.cs
- PropertyRecord.cs
- AppDomainProtocolHandler.cs
- CFStream.cs
- FlowLayoutPanel.cs
- AccessControlList.cs
- StickyNote.cs
- ApplicationBuildProvider.cs
- ObjectDataSourceView.cs
- Container.cs
- DynamicEndpoint.cs
- PolyLineSegment.cs
- DataServiceQueryException.cs
- DataGridViewLinkCell.cs
- DataGridViewSelectedRowCollection.cs
- _HeaderInfo.cs
- RemoteWebConfigurationHostStream.cs
- HttpRuntime.cs
- StylusLogic.cs
- PeerApplicationLaunchInfo.cs
- SQLBinary.cs
- HeaderCollection.cs
- ServiceTimeoutsElement.cs
- InheritanceAttribute.cs
- Timer.cs
- Ops.cs
- CompatibleComparer.cs
- PrtTicket_Public.cs
- TimeZone.cs
- ManagedFilter.cs
- UrlPath.cs
- IntAverageAggregationOperator.cs
- NonVisualControlAttribute.cs
- WebPartConnectVerb.cs
- EnumUnknown.cs
- InstancePersistenceException.cs
- CompilerGeneratedAttribute.cs
- Stack.cs
- WindowsSolidBrush.cs
- WarningException.cs
- SoapConverter.cs
- AsyncOperation.cs
- DataGridLinkButton.cs
- RowCache.cs
- ComUdtElement.cs
- XpsResource.cs
- ExtendedPropertyCollection.cs
- TraceUtility.cs
- PseudoWebRequest.cs
- ZipPackage.cs
- CachedFontFace.cs
- ComponentDesigner.cs
- WCFBuildProvider.cs
- DataGridViewCheckBoxCell.cs
- MarkupWriter.cs
- CatalogZone.cs
- DoubleAnimationBase.cs
- SafeProcessHandle.cs
- ConfigurationErrorsException.cs
- DesignerProperties.cs
- AsymmetricSignatureDeformatter.cs
- DbModificationCommandTree.cs
- DbReferenceCollection.cs
- WindowsFormsLinkLabel.cs
- TailCallAnalyzer.cs
- ListenerElementsCollection.cs
- ProviderIncompatibleException.cs
- Attributes.cs
- DefaultPropertyAttribute.cs
- WindowsSysHeader.cs
- SiteMap.cs
- FixedPageStructure.cs
- Walker.cs
- UpDownEvent.cs
- PropertyGroupDescription.cs
- InkCanvas.cs
- SoapFormatExtensions.cs
- StylusButtonEventArgs.cs
- Item.cs
- ListChangedEventArgs.cs
- StylusDownEventArgs.cs
- ToolBar.cs
- PopupEventArgs.cs
- OperationCanceledException.cs
- AlternateView.cs
- IOException.cs
- SafeCryptoHandles.cs
- DataGridBoolColumn.cs
- Trigger.cs
- TextEvent.cs
- MultipleViewPattern.cs
- ControlPager.cs