WPF 按钮点击音效实现

news2025/6/4 0:46:29

WPF 按钮点击音效实现

下面我将为您提供一个完整的 WPF 按钮点击音效实现方案,包含多种实现方式和高级功能:

完整实现方案

MainWindow.xaml

<Window x:Class="ButtonClickSound.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ButtonClickSound"
        mc:Ignorable="d"
        Title="按钮点击音效演示" 
        Height="450" 
        Width="800"
        WindowStartupLocation="CenterScreen"
        Background="#FF1E1E1E">
    
    <Window.Resources>
        <!-- 音效资源 -->
        <MediaPlayer x:Key="ClickSoundPlayer" Source="sounds/click.wav" Volume="0.7"/>
        <MediaPlayer x:Key="HoverSoundPlayer" Source="sounds/hover.wav" Volume="0.5"/>
        
        <!-- 按钮样式 -->
        <Style x:Key="SoundButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="#FF252526"/>
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="BorderBrush" Value="#FF3F3F46"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="FontSize" Value="18"/>
            <Setter Property="Padding" Value="20,10"/>
            <Setter Property="Margin" Value="10"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="border" 
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="8">
                            <ContentPresenter HorizontalAlignment="Center" 
                                              VerticalAlignment="Center"
                                              Margin="{TemplateBinding Padding}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="#FF3A80D2"/>
                                <Setter Property="BorderBrush" Value="#FF2A70C2"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background" Value="#FF2A70C2"/>
                                <Setter Property="BorderBrush" Value="#FF1A60B2"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <!-- 标题 -->
        <TextBlock Text="按钮点击音效演示" 
                   Grid.Row="0"
                   FontSize="28"
                   FontWeight="Bold"
                   Foreground="White"
                   HorizontalAlignment="Center"
                   Margin="0,20"/>
        
        <!-- 按钮区域 -->
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            
            <!-- 简单实现 -->
            <StackPanel Grid.Column="0" 
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center">
                <TextBlock Text="简单实现" 
                           FontSize="20"
                           Foreground="#AAAAAA"
                           HorizontalAlignment="Center"
                           Margin="0,0,0,20"/>
                
                <!-- 直接绑定事件 -->
                <Button Content="事件处理器" 
                        Style="{StaticResource SoundButtonStyle}"
                        Click="ButtonWithEventHandler_Click"/>
                
                <!-- 使用行为 -->
                <Button Content="使用行为" 
                        Style="{StaticResource SoundButtonStyle}"
                        local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/>
                
                <!-- 使用命令 -->
                <Button Content="使用命令" 
                        Style="{StaticResource SoundButtonStyle}"
                        Command="{Binding PlaySoundCommand}"/>
            </StackPanel>
            
            <!-- 高级实现 -->
            <StackPanel Grid.Column="1" 
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center">
                <TextBlock Text="高级实现" 
                           FontSize="20"
                           Foreground="#AAAAAA"
                           HorizontalAlignment="Center"
                           Margin="0,0,0,20"/>
                
                <!-- 悬停+点击音效 -->
                <Button Content="悬停+点击音效" 
                        Style="{StaticResource SoundButtonStyle}"
                        local:SoundBehavior.HoverSound="{StaticResource HoverSoundPlayer}"
                        local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/>
                
                <!-- 自定义音效 -->
                <Button Content="自定义音效" 
                        Style="{StaticResource SoundButtonStyle}"
                        local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"
                        Click="CustomSoundButton_Click"/>
                
                <!-- 随机音效 -->
                <Button Content="随机音效" 
                        Style="{StaticResource SoundButtonStyle}"
                        Click="RandomSoundButton_Click"/>
            </StackPanel>
        </Grid>
        
        <!-- 控制面板 -->
        <Border Grid.Row="2"
                Background="#202020"
                CornerRadius="10"
                Padding="20"
                Margin="20"
                HorizontalAlignment="Center">
            <StackPanel Orientation="Horizontal" Spacing="20">
                <Button Content="播放点击音效" 
                        Style="{StaticResource SoundButtonStyle}"
                        Click="PlaySound_Click"/>
                <Button Content="停止所有音效" 
                        Style="{StaticResource SoundButtonStyle}"
                        Click="StopAllSounds_Click"/>
                <Button Content="切换静音模式" 
                        Style="{StaticResource SoundButtonStyle}"
                        Click="ToggleMute_Click"/>
            </StackPanel>
        </Border>
    </Grid>
</Window>

SoundBehavior.cs (音效行为类)

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace ButtonClickSound
{
    public static class SoundBehavior
    {
        #region ClickSound 附加属性
        public static MediaPlayer GetClickSound(DependencyObject obj)
        {
            return (MediaPlayer)obj.GetValue(ClickSoundProperty);
        }

        public static void SetClickSound(DependencyObject obj, MediaPlayer value)
        {
            obj.SetValue(ClickSoundProperty, value);
        }

        public static readonly DependencyProperty ClickSoundProperty =
            DependencyProperty.RegisterAttached("ClickSound", typeof(MediaPlayer), typeof(SoundBehavior), 
                new PropertyMetadata(null, OnClickSoundChanged));

        private static void OnClickSoundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is Button button)
            {
                button.Click -= Button_Click;
                
                if (e.NewValue != null)
                {
                    button.Click += Button_Click;
                }
            }
        }

        private static void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Button button)
            {
                var player = GetClickSound(button);
                if (player != null)
                {
                    player.Position = TimeSpan.Zero;
                    player.Play();
                }
            }
        }
        #endregion

        #region HoverSound 附加属性
        public static MediaPlayer GetHoverSound(DependencyObject obj)
        {
            return (MediaPlayer)obj.GetValue(HoverSoundProperty);
        }

        public static void SetHoverSound(DependencyObject obj, MediaPlayer value)
        {
            obj.SetValue(HoverSoundProperty, value);
        }

        public static readonly DependencyProperty HoverSoundProperty =
            DependencyProperty.RegisterAttached("HoverSound", typeof(MediaPlayer), typeof(SoundBehavior), 
                new PropertyMetadata(null, OnHoverSoundChanged));

        private static void OnHoverSoundChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is Button button)
            {
                button.MouseEnter -= Button_MouseEnter;
                
                if (e.NewValue != null)
                {
                    button.MouseEnter += Button_MouseEnter;
                }
            }
        }

        private static void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            if (sender is Button button)
            {
                var player = GetHoverSound(button);
                if (player != null)
                {
                    player.Position = TimeSpan.Zero;
                    player.Play();
                }
            }
        }
        #endregion
    }
}

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace ButtonClickSound
{
    public partial class MainWindow : Window
    {
        // 全局音效播放器
        private MediaPlayer _globalClickPlayer = new MediaPlayer();
        
        // 随机音效列表
        private List<MediaPlayer> _randomSounds = new List<MediaPlayer>();
        private Random _random = new Random();
        
        // 静音状态
        private bool _isMuted = false;

        public ICommand PlaySoundCommand { get; }

        public MainWindow()
        {
            InitializeComponent();
            LoadSounds();
            
            // 初始化命令
            PlaySoundCommand = new RelayCommand(ExecutePlaySound);
            
            DataContext = this;
        }

        private void LoadSounds()
        {
            try
            {
                // 初始化全局点击音效
                _globalClickPlayer.Open(new Uri("sounds/click.wav", UriKind.Relative));
                _globalClickPlayer.Volume = 0.7;
                
                // 初始化随机音效
                _randomSounds.Add(CreateSoundPlayer("sounds/click1.wav", 0.7));
                _randomSounds.Add(CreateSoundPlayer("sounds/click2.wav", 0.6));
                _randomSounds.Add(CreateSoundPlayer("sounds/click3.wav", 0.8));
                _randomSounds.Add(CreateSoundPlayer("sounds/click4.wav", 0.5));
            }
            catch (Exception ex)
            {
                MessageBox.Show($"加载音效失败: {ex.Message}", "错误", 
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private MediaPlayer CreateSoundPlayer(string path, double volume)
        {
            var player = new MediaPlayer();
            player.Open(new Uri(path, UriKind.Relative));
            player.Volume = volume;
            return player;
        }

        #region 简单实现方法
        
        // 方法1: 直接在事件处理器中播放音效
        private void ButtonWithEventHandler_Click(object sender, RoutedEventArgs e)
        {
            PlayGlobalClickSound();
        }
        
        // 方法2: 使用命令播放音效
        private void ExecutePlaySound()
        {
            PlayGlobalClickSound();
        }
        
        #endregion

        #region 高级实现方法
        
        // 自定义音效按钮
        private void CustomSoundButton_Click(object sender, RoutedEventArgs e)
        {
            // 创建临时音效播放器
            var player = new MediaPlayer();
            player.Open(new Uri("sounds/special_click.wav", UriKind.Relative));
            player.Volume = 0.8;
            player.Play();
            
            // 播放完成后自动释放资源
            player.MediaEnded += (s, args) => player.Close();
        }
        
        // 随机音效按钮
        private void RandomSoundButton_Click(object sender, RoutedEventArgs e)
        {
            if (_randomSounds.Count == 0) return;
            
            int index = _random.Next(0, _randomSounds.Count);
            var player = _randomSounds[index];
            
            player.Position = TimeSpan.Zero;
            player.Play();
        }
        
        #endregion

        #region 控制面板方法
        
        private void PlaySound_Click(object sender, RoutedEventArgs e)
        {
            PlayGlobalClickSound();
        }
        
        private void StopAllSounds_Click(object sender, RoutedEventArgs e)
        {
            _globalClickPlayer.Stop();
            
            foreach (var player in _randomSounds)
            {
                player.Stop();
            }
        }
        
        private void ToggleMute_Click(object sender, RoutedEventArgs e)
        {
            _isMuted = !_isMuted;
            
            // 设置全局音量
            double volume = _isMuted ? 0.0 : 0.7;
            _globalClickPlayer.Volume = volume;
            
            foreach (var player in _randomSounds)
            {
                player.Volume = volume;
            }
            
            // 更新按钮文本
            ((Button)sender).Content = _isMuted ? "取消静音" : "切换静音模式";
        }
        
        #endregion

        private void PlayGlobalClickSound()
        {
            _globalClickPlayer.Position = TimeSpan.Zero;
            _globalClickPlayer.Play();
        }
    }
    
    // 命令实现
    public class RelayCommand : ICommand
    {
        private readonly Action _execute;
        private readonly Func<bool> _canExecute;

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public RelayCommand(Action execute, Func<bool> canExecute = null)
        {
            _execute = execute ?? throw new ArgumentNullException(nameof(execute));
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true;

        public void Execute(object parameter) => _execute();
    }
}

实现方法详解

1. 简单实现方法

方法1: 直接在事件处理器中播放音效
private void ButtonWithEventHandler_Click(object sender, RoutedEventArgs e)
{
    // 创建或使用全局播放器
    var player = new MediaPlayer();
    player.Open(new Uri("sounds/click.wav", UriKind.Relative));
    player.Play();
    
    // 或者使用全局播放器
    _globalClickPlayer.Position = TimeSpan.Zero;
    _globalClickPlayer.Play();
}
方法2: 使用附加行为
<Button Content="使用行为" 
        local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/>

2. 高级实现方法

悬停+点击音效组合
<Button Content="悬停+点击音效" 
        local:SoundBehavior.HoverSound="{StaticResource HoverSoundPlayer}"
        local:SoundBehavior.ClickSound="{StaticResource ClickSoundPlayer}"/>
自定义音效
private void CustomSoundButton_Click(object sender, RoutedEventArgs e)
{
    // 创建临时音效播放器
    var player = new MediaPlayer();
    player.Open(new Uri("sounds/special_click.wav", UriKind.Relative));
    player.Play();
    
    // 播放完成后自动释放资源
    player.MediaEnded += (s, args) => player.Close();
}
随机音效
private void RandomSoundButton_Click(object sender, RoutedEventArgs e)
{
    if (_randomSounds.Count == 0) return;
    
    int index = _random.Next(0, _randomSounds.Count);
    var player = _randomSounds[index];
    
    player.Position = TimeSpan.Zero;
    player.Play();
}

3. 使用命令实现

public ICommand PlaySoundCommand { get; }

public MainWindow()
{
    PlaySoundCommand = new RelayCommand(ExecutePlaySound);
}

private void ExecutePlaySound()
{
    PlayGlobalClickSound();
}

// XAML
<Button Content="使用命令" Command="{Binding PlaySoundCommand}"/>

高级功能实现

1. 音效管理

// 全局音效管理器
public static class SoundManager
{
    private static readonly Dictionary<string, MediaPlayer> _sounds = new Dictionary<string, MediaPlayer>();
    private static double _globalVolume = 0.7;
    private static bool _isMuted = false;

    public static void LoadSound(string name, string path, double volume = 1.0)
    {
        if (_sounds.ContainsKey(name)) return;
        
        var player = new MediaPlayer();
        player.Open(new Uri(path, UriKind.Relative));
        player.Volume = volume * _globalVolume;
        _sounds[name] = player;
    }

    public static void PlaySound(string name)
    {
        if (_isMuted || !_sounds.TryGetValue(name, out var player)) return;
        
        player.Position = TimeSpan.Zero;
        player.Play();
    }

    public static void SetGlobalVolume(double volume)
    {
        _globalVolume = volume;
        foreach (var player in _sounds.Values)
        {
            player.Volume = volume;
        }
    }

    public static void SetMute(bool isMuted)
    {
        _isMuted = isMuted;
    }
}

// 使用
SoundManager.LoadSound("click", "sounds/click.wav", 0.7);
SoundManager.PlaySound("click");

2. 3D音效效果

private void PlayPositionalSound(Point position)
{
    // 计算相对于窗口中心的位置
    double centerX = ActualWidth / 2;
    double centerY = ActualHeight / 2;
    
    // 计算相对位置 (-1 到 1)
    double relX = (position.X - centerX) / centerX;
    double relY = (position.Y - centerY) / centerY;
    
    // 创建音效播放器
    var player = new MediaPlayer();
    player.Open(new Uri("sounds/click.wav", UriKind.Relative));
    
    // 应用平衡效果 (左右声道)
    player.Balance = Math.Clamp(relX, -1.0, 1.0);
    
    // 应用音量衰减
    double distance = Math.Sqrt(relX * relX + relY * relY);
    player.Volume = Math.Clamp(1.0 - distance * 0.5, 0.2, 1.0);
    
    player.Play();
}

3. 音效池系统

public class SoundPool
{
    private readonly List<MediaPlayer> _players = new List<MediaPlayer>();
    private readonly string _soundPath;
    private readonly double _volume;
    private int _currentIndex = 0;

    public SoundPool(string soundPath, int poolSize = 5, double volume = 1.0)
    {
        _soundPath = soundPath;
        _volume = volume;
        
        // 初始化播放器池
        for (int i = 0; i < poolSize; i++)
        {
            var player = new MediaPlayer();
            player.Open(new Uri(soundPath, UriKind.Relative));
            player.Volume = volume;
            _players.Add(player);
        }
    }

    public void Play()
    {
        // 选择下一个播放器
        var player = _players[_currentIndex];
        
        // 重置位置
        player.Position = TimeSpan.Zero;
        player.Play();
        
        // 移动到下一个播放器
        _currentIndex = (_currentIndex + 1) % _players.Count;
    }
}

// 使用
private SoundPool _clickSoundPool = new SoundPool("sounds/click.wav", 5, 0.7);

private void Button_Click(object sender, RoutedEventArgs e)
{
    _clickSoundPool.Play();
}

专业建议

1. 音效文件处理

  • 使用16位PCM WAV格式以获得最佳兼容性
  • 保持音效文件短小(通常小于500ms)
  • 使用44.1kHz采样率
  • 预加载常用音效以减少延迟

2. 性能优化

// 预加载音效
private void PreloadSounds()
{
    // 使用后台线程预加载
    Task.Run(() =>
    {
        var player = new MediaPlayer();
        player.Open(new Uri("sounds/click.wav", UriKind.Relative));
        
        // 预读到内存
        player.Play();
        player.Pause();
        player.Position = TimeSpan.Zero;
    });
}

// 使用NAudio进行低延迟播放
private void PlayLowLatencySound(string path)
{
    using (var audioFile = new AudioFileReader(path))
    using (var outputDevice = new WaveOutEvent())
    {
        outputDevice.Init(audioFile);
        outputDevice.Play();
    }
}

3. 无障碍支持

// 检查用户是否启用了声音
private bool IsSoundEnabled()
{
    // 检查系统设置
    bool systemSoundEnabled = SystemParameters.ClientAudioPlayback;
    
    // 检查用户偏好
    bool userPreference = Properties.Settings.Default.SoundEnabled;
    
    return systemSoundEnabled && userPreference;
}

// 提供视觉反馈替代
private void PlaySoundWithVisualFeedback()
{
    if (IsSoundEnabled())
    {
        PlayGlobalClickSound();
    }
    else
    {
        // 提供视觉反馈
        var button = sender as Button;
        var originalBrush = button.Background;
        
        button.Background = Brushes.Gray;
        
        // 短暂延迟后恢复
        Task.Delay(100).ContinueWith(_ => 
        {
            Dispatcher.Invoke(() => button.Background = originalBrush);
        });
    }
}

这个实现提供了多种按钮点击音效的实现方式,从简单的直接事件处理到高级的音效管理系统和3D音效效果。您可以根据项目需求选择合适的实现方法,

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2395290.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

编写测试用例

测试用例&#xff08;Test Case&#xff09;是用于测试系统的要素集合 目录 编写测试用例作用 编写测试用例要包含七大元素 测试用例的设计方法 1、等价类法 2、边界值法 3、正交表法 4、判定表法 5、错误推测法 6、场景法 编写测试用例作用 1、确保功能全面覆盖…

每日Prompt:隐形人

提示词 黑色棒球帽&#xff0c;白色抹胸、粉色低腰短裙、白色襪子&#xff0c;黑色鞋子&#xff0c;粉紅色背包&#xff0c;衣服悬浮在空中呈现动态姿势&#xff0c;虚幻引擎渲染风格&#xff0c;高清晰游戏CG质感&#xff0c;户外山林背景&#xff0c;画面聚焦在漂浮的衣服上…

TensorFlow深度学习实战(19)——受限玻尔兹曼机

TensorFlow深度学习实战&#xff08;19&#xff09;——受限玻尔兹曼机 0. 前言1. 受限玻尔兹曼机1.1 受限玻尔兹曼机架构1.2 受限玻尔兹曼机的数学原理 2. 使用受限玻尔兹曼机重建图像3. 深度信念网络小结系列链接 0. 前言 受限玻尔兹曼机 (Restricted Boltzmann Machine, RB…

告别手动绘图!基于AI的Smart Mermaid自动可视化图表工具搭建与使用指南

以下是对Smart Mermaid的简单介绍&#xff1a; 一款基于 AI 技术的 Web 应用程序&#xff0c;可将文本内容智能转换为 Mermaid 格式的代码&#xff0c;并将其渲染成可视化图表可以智能制作流程图、序列图、甘特图、状态图等等&#xff0c;并且支持在线调整、图片导出可以Docke…

【Oracle】安装单实例

个人主页&#xff1a;Guiat 归属专栏&#xff1a;Oracle 文章目录 1. 安装前的准备工作1.1 硬件和系统要求1.2 检查系统环境1.3 下载Oracle软件 2. 系统配置2.1 创建Oracle用户和组2.2 配置内核参数2.3 配置用户资源限制2.4 安装必要的软件包 3. 目录结构和环境变量3.1 创建Ora…

QT中更新或添加组件时出现“”qt操作至少需要一个处于启用状态的有效资料档案库“解决方法”

在MaintenanceTool.exe中点击下一步 第一个&#xff1a; 第二个&#xff1a; 第三个&#xff1a; 以上任意一个放入资料库中

论文速读《UAV-Flow Colosseo: 自然语言控制无人机系统》

论文链接&#xff1a;https://arxiv.org/abs/2505.15725项目主页&#xff1a;https://prince687028.github.io/UAV-Flow/ 0. 简介 近年来&#xff0c;无人机技术蓬勃发展&#xff0c;但如何让无人机像智能助手一样理解并执行人类语言指令&#xff0c;仍是一个前沿挑战。现有研…

ES6+中Promise 中错误捕捉详解——链式调用catch()或者async/await+try/catch

通过 unhandledrejection 捕捉未处理的 Promise 异常&#xff0c;手动将其抛出&#xff0c;最终让 window.onerror 捕捉&#xff0c;从而统一所有异常的处理逻辑 规范代码&#xff1a;catch&#xff08;onRejected&#xff09;、async...awaittry...catch 在 JavaScript 的 Pro…

解常微分方程组

Euler法 function euler_method % 参数设置 v_missile 450; % 导弹速度 km/h v_enemy 90; % 敌艇速度 km/h % 初始条件 x0 0; % 导弹初始位置 x y0 0; % 导弹初始位置 y xe0 120; % 敌艇初始位置 y t0 0; % 初始时间 % 时间步长和总时间 dt 0.01; % 时间步长 t_final …

C++实现汉诺塔游戏自动完成

目录 一、汉诺塔的规则二、数学递归推导式三、步骤实现(一)汉诺塔模型(二)递归实现(三)显示1.命令行显示2.SDL图形显示 四、处理用户输入及SDL环境配置五、总结六、源码下载 一、汉诺塔的规则 游戏由3根柱子和若干大小不一的圆盘组成&#xff0c;初始状态下&#xff0c;所有的…

pikachu靶场通关笔记07 XSS关卡03-存储型XSS

目录 一、XSS 二、存储型XSS 三、源码分析 四、渗透实战 1、输入mooyuan试一试 2、注入Payload 3、查看数据库 4、再次进入留言板页面 本系列为通过《pikachu靶场通关笔记》的XSS关卡(共10关&#xff09;渗透集合&#xff0c;通过对XSS关卡源码的代码审计找到XSS风险的…

OpenCV CUDA模块直方图计算------用于在 GPU 上执行对比度受限的自适应直方图均衡类cv::cuda::CLAHE

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 cv::cuda::CLAHE 是 OpenCV 的 CUDA 模块中提供的一个类&#xff0c;用于在 GPU 上执行对比度受限的自适应直方图均衡&#xff08;Contrast Limi…

华为OD机试真题——矩形绘制(2025A卷:200分)Java/python/JavaScript/C/C++/GO最佳实现

2025 A卷 200分 题型 本专栏内全部题目均提供Java、python、JavaScript、C、C++、GO六种语言的最佳实现方式; 并且每种语言均涵盖详细的问题分析、解题思路、代码实现、代码详解、3个测试用例以及综合分析; 本文收录于专栏:《2025华为OD真题目录+全流程解析+备考攻略+经验分…

JDBC连不上mysql:Unable to load authentication plugin ‘caching_sha2_password‘.

最近为一个spring-boot项目下了mysql-9.3.0&#xff0c;结果因为mysql版本太新一直报错连不上。 错误如下&#xff1a; 2025-06-01 16:19:43.516 ERROR 22088 --- [http-nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispat…

MacOS安装Docker Desktop并汉化

1. 安装Docker Desktop 到Docker Desktop For Mac下载对应系统的Docker Desktop 安装包&#xff0c;下载后安装&#xff0c;没有账号需要注册&#xff0c;然后登陆即可。 2. 汉化 前往汉化包下载链接下载对应系统的.asar文件 然后将安装好的文件覆盖原先的文件app.asar文件…

Centos系统搭建主备DNS服务

目录 一、主DNS服务器配置 1.安装 BIND 软件包 2.配置主配置文件 3.创建正向区域文件 4.创建区域数据文件 5.检查配置语法并重启服务 二、从DNS服务配置 1.安装 BIND 软件包 2.配置主配置文件 3.创建缓存目录 4.启动并设置开机自启 一、主DNS服务器配置 1.安装 BIN…

使用 HTML + JavaScript 实现在线考试系统

在现代的在线教育平台中&#xff0c;在线考试系统是不可或缺的一部分。本文将通过一个完整的示例&#xff0c;演示如何使用 HTML、CSS 和 JavaScript 构建一个支持多种题型的在线考试系统。 效果演示 项目概述 本项目主要包含以下核心功能&#xff1a; 支持4种常见题型&…

谷歌工作自动化——仙盟大衍灵机——仙盟创梦IDE

下载地址 https://chromewebstore.google.com/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd https://chrome.zzzmh.cn/info/mooikfkahbdckldjjndioackbalphokd

秒杀系统—1.架构设计和方案简介

大纲 1.秒杀系统的方案设计要点 2.秒杀系统的数据 页面 接口的处理方案 3.秒杀系统的负载均衡方案底层相关 4.秒杀系统的限流机制和超卖问题处理 5.秒杀系统的异步下单和高可用方案 1.秒杀系统的方案设计要点 (1)秒杀促销活动的数据处理 (2)秒杀促销活动的页面处理 (…

基于FashionMnist数据集的自监督学习(生成式自监督学习AE算法)

目录 一&#xff0c;生成式自监督学习 1.1 简介 1.2 核心思想 1.3 常见算法 1.3.1 自动编码器&#xff08;Autoencoder&#xff09; 1.3.2 生成对抗网络&#xff08;GANs&#xff09; 1.3.3 变分自编码器&#xff08;VAE&#xff09; 1.3.4 Transformer-based 模型&…