当前位置: 首页>>代码示例>>C#>>正文


C# SafeMILHandle.Dispose方法代码示例

本文整理汇总了C#中System.Windows.Media.SafeMILHandle.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SafeMILHandle.Dispose方法的具体用法?C# SafeMILHandle.Dispose怎么用?C# SafeMILHandle.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.SafeMILHandle的用法示例。


在下文中一共展示了SafeMILHandle.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ColorContext

        private ColorContext(SafeMILHandle colorContextHandle)
        {
            _colorContextHandle = colorContextHandle;

            //
            // For 3.* backwards compat, we aren't going to HRESULT.Check() anywhere because
            // that could introduce new exceptions. If anything fails, _colorContextHelper
            // will be invalid and we'll emulate the old failure behavior later in
            // OpenProfileStream()
            //
            
            IWICCC.WICColorContextType type;
            if (HRESULT.Failed(IWICCC.GetType(_colorContextHandle, out type)))
            {
                return;
            }

            switch (type)
            {
                case IWICCC.WICColorContextType.WICColorContextProfile:
                    uint cbProfileActual;
                    int hr = IWICCC.GetProfileBytes(_colorContextHandle, 0, null, out cbProfileActual);
                    if (HRESULT.Succeeded(hr) && cbProfileActual != 0)
                    {
                        byte[] profileData = new byte[cbProfileActual];
                        if (HRESULT.Failed(IWICCC.GetProfileBytes(
                            _colorContextHandle, cbProfileActual, profileData, out cbProfileActual))
                            )
                        {
                            return;
                        }
                        
                        FromRawBytes(profileData, (int)cbProfileActual, /* dontThrowException = */ true);
                    }

                    break;

                case IWICCC.WICColorContextType.WICColorContextExifColorSpace:
                    uint colorSpace;
                    if (HRESULT.Failed(IWICCC.GetExifColorSpace(_colorContextHandle, out colorSpace)))
                    {
                        return;
                    }

                    //
                    // From MSDN:
                    //     "1" is sRGB. We will use our built-in sRGB profile.
                    //     "2" is Adobe RGB. WIC says we should never see this because they are nonstandard and instead a 
                    //     real profile will be returned.
                    //     "3-65534" is unused.
                    //
                    // From the Exif spec:
                    //     B. Tag Relating to Color Space
                    //     ColorSpace
                    //
                    //     The color space information tag (ColorSpace) is always recorded as the color space specifier.
                    //     Normally sRGB (=1) is used to define the color space based on the PC monitor conditions and environment. If a
                    //     color space other than sRGB is used, Uncalibrated (=FFFF.H) is set. Image data recorded as Uncalibrated can be
                    //     treated as sRGB when it is converted to Flashpix. On sRGB see Annex E.
                    //     Tag = 40961 (A001.H)
                    //     Type = SHORT
                    //     Count = 1
                    //     1 = sRGB
                    //     FFFF.H = Uncalibrated
                    //
                    // So for 65535 we will return sRGB since it is acceptible rather than having an invalid ColorContext. The Exif 
                    // CC should always be the second one so the real one is given priority. Alternatively, we could ignore the
                    // uncalibrated CC but that would be a breaking change with 3.* (returning 1 instead of 2).
                    //
                    // If anything other than 1 or 65535 happens, _colorContextHelper will remain invalid and we will emulate
                    // the old crash behavior in OpenProfileStream().
                    //
                    
                    if (colorSpace == 1 || colorSpace == 65535)
                    {
                        ResourceManager resourceManager = new ResourceManager(
                            _colorProfileResources, Assembly.GetAssembly(typeof(ColorContext))
                            );
                        byte[] sRGBProfile = (byte[])resourceManager.GetObject(_sRGBProfileName);
                        // The existing ColorContext has already been initialized as Exif so we can't initialize it again
                        // and instead must create a new one.
                        using (FactoryMaker factoryMaker = new FactoryMaker())
                        {
                            _colorContextHandle.Dispose();
                            _colorContextHandle = null;
                            
                            if (HRESULT.Failed(UnsafeNativeMethodsMilCoreApi.WICCodec.CreateColorContext(
                                factoryMaker.ImagingFactoryPtr, out _colorContextHandle))
                                )
                            {
                                return;
                            }

                            if (HRESULT.Failed(IWICCC.InitializeFromMemory(
                                _colorContextHandle, sRGBProfile, (uint)sRGBProfile.Length))
                                )
                            {
                                return;
                            }
                        }
//.........这里部分代码省略.........
开发者ID:JianwenSun,项目名称:cc,代码行数:101,代码来源:ColorContext.cs


注:本文中的System.Windows.Media.SafeMILHandle.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。