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
- HttpCapabilitiesSectionHandler.cs
- CodeAccessSecurityEngine.cs
- DataServiceHost.cs
- HttpListener.cs
- FontFamilyValueSerializer.cs
- embossbitmapeffect.cs
- TextBox.cs
- CodeEntryPointMethod.cs
- ObjectItemAssemblyLoader.cs
- LifetimeServices.cs
- ServicesUtilities.cs
- Win32.cs
- ReflectTypeDescriptionProvider.cs
- ErrorHandler.cs
- SQLInt32.cs
- RepeaterItem.cs
- DataColumnChangeEvent.cs
- WeakRefEnumerator.cs
- DataGridView.cs
- AutoGeneratedFieldProperties.cs
- ExcCanonicalXml.cs
- safePerfProviderHandle.cs
- ParentUndoUnit.cs
- ParsedAttributeCollection.cs
- ExportOptions.cs
- localization.cs
- ReaderContextStackData.cs
- AmbientLight.cs
- WebControlAdapter.cs
- TickBar.cs
- EventData.cs
- SectionInput.cs
- ThemeDirectoryCompiler.cs
- DeleteWorkflowOwnerCommand.cs
- UnsafeNativeMethods.cs
- propertytag.cs
- InfiniteIntConverter.cs
- ColumnCollectionEditor.cs
- InstanceLockLostException.cs
- XpsS0ValidatingLoader.cs
- SignedXml.cs
- ScriptControlDescriptor.cs
- NullableBoolConverter.cs
- PasswordTextNavigator.cs
- RadioButton.cs
- ValidationError.cs
- ConfigXmlSignificantWhitespace.cs
- RequestCachingSection.cs
- BindStream.cs
- DataSourceHelper.cs
- CodeDelegateInvokeExpression.cs
- ConstantSlot.cs
- Transform3D.cs
- CursorEditor.cs
- QueryContinueDragEvent.cs
- Utils.cs
- InvalidComObjectException.cs
- GridViewRowPresenter.cs
- DES.cs
- PseudoWebRequest.cs
- ValueQuery.cs
- ServicePointManager.cs
- SafeUserTokenHandle.cs
- invalidudtexception.cs
- StorageMappingFragment.cs
- SqlGenerator.cs
- ClientScriptManager.cs
- NGCSerializationManagerAsync.cs
- Subtree.cs
- PeerContact.cs
- ParentUndoUnit.cs
- CultureSpecificCharacterBufferRange.cs
- FilterQuery.cs
- StylusPointPropertyId.cs
- OleDbStruct.cs
- InputScopeAttribute.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- SoapMessage.cs
- KeyValueInternalCollection.cs
- Registration.cs
- FormatStringEditor.cs
- MenuRendererStandards.cs
- RegularExpressionValidator.cs
- TextElementEnumerator.cs
- TreeViewDesigner.cs
- PageParserFilter.cs
- ProcessStartInfo.cs
- MultipartContentParser.cs
- MaskedTextProvider.cs
- CompilationUtil.cs
- BitmapEffectGroup.cs
- PropertyItem.cs
- URLAttribute.cs
- AppDomainUnloadedException.cs
- ParseChildrenAsPropertiesAttribute.cs
- PngBitmapDecoder.cs
- ReadOnlyObservableCollection.cs
- ShapingWorkspace.cs
- ConfigurationElement.cs
- SiteMapSection.cs