TMusic/Tool/IconHelper.cs

(开头部分) 10KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace TMusic.Tool
{
    [SuppressMessage("ReSharper", "ArrangeRedundantParentheses")]
    [SuppressMessage("ReSharper", "IntVariableOverflowInUncheckedContext")]
    internal static class IconHelper
    {
        private static Size SmallIconSize;

        private static Size IconSize;

        private static int SystemBitDepth;

        [SecurityCritical, SecuritySafeCritical]
        public static void GetIconHandlesFromImageSource(ImageSource image, out IconHandle largeIconHandle, out IconHandle smallIconHandle)
        {
            EnsureSystemMetrics();
            largeIconHandle = CreateIconHandleFromImageSource(image, IconSize);
            smallIconHandle = CreateIconHandleFromImageSource(image, SmallIconSize);
        }

        [SecurityCritical]
        public static IconHandle CreateIconHandleFromImageSource(ImageSource image, Size size)
        {
            EnsureSystemMetrics();

            var asGoodAsItGets = false;

            var bf = image as BitmapFrame;
            if (bf?.Decoder?.Frames != null)
            {
                bf = GetBestMatch(bf.Decoder.Frames, size);

                asGoodAsItGets = bf.Decoder is IconBitmapDecoder || bf.PixelWidth == (int) size.Width && bf.PixelHeight == (int) size.Height;

                image = bf;
            }

            if (!asGoodAsItGets)
            {
                bf = BitmapFrame.Create(GenerateBitmapSource(image, size));
            }

            return CreateIconHandleFromBitmapFrame(bf);
        }

        [SecurityCritical]
        private static IconHandle CreateIconHandleFromBitmapFrame(BitmapFrame sourceBitmapFrame)
        {
            BitmapSource bitmapSource = sourceBitmapFrame;

            if (bitmapSource.Format != PixelFormats.Bgra32 && bitmapSource.Format != PixelFormats.Pbgra32)
后面还有 236 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。