当前位置:首页 > 编程学习 > C# 图片渐淡切换

C# 图片渐淡切换

编程学习2021-07-2552000


通过Color.FromArgb里的A,也就是透明度的变化来实现图片渐淡切换的效果。

看图:

C# 图片渐淡切换.gif 图片渐淡切换  编程 技术 .NET 第1张


代码很简单,picbox的图片增加透明度,直到完全透明,这样picbox的背景图会渐渐显示出来了。

private void button1_Click(object sender, EventArgs e)
{
    swapImg();
}

private void swapImg()
{
    picbox.BackgroundImage = Properties.Resources.pic2;
    Bitmap pic = (Bitmap)Properties.Resources.pic1.Clone();
    for (int i = 255; i >= 0; i -= 15)
    {
        for (int j = 0; j < pic.Height; j++)
        {
            for (int k = 0; k < pic.Width; k++)
            {
                Color c = Color.FromArgb(i, pic.GetPixel(j, k));
                pic.SetPixel(j, k, c);
            }
        }

        picbox.Image = pic;
        picbox.Update();
        System.Threading.Thread.Sleep(50);
        Application.DoEvents();
    }
    pic.Dispose();
}



Color.FromArgb(Int32, Color)方法

public static System.Drawing.Color FromArgb (int alpha, System.Drawing.Color baseColor);


从指定的Color结构baseColor创建一个新的有透明度的Color,尽管此方法允许为alpha传递32位的值,但该值仅限于8位。



参数

alpha:Int32

新颜色的透明度,有效值为 0 到 255。


baseColor:Color

基于该颜色创造新的颜色。


返回值

Color

返回创建的颜色。




扫描二维码推送至手机访问。

版权声明:本文由海阔天空发布,如需转载请注明出处。

本文链接:https://www.apull.net/html/20210725195715.html

分享给朋友:

相关文章

VB连接SQLServer数据库操作代码

VB连接SQLServer数据库操作代码

第一步,在ModConString模块中定义一系列变量'定义一个属性过程反映连接字符串Public Property Get conString() As Variant conString = "data source=.;initial catalog=Sims_four;user End Property'定义一个提供者反映数据库类型Public Property Get conProvide() As Variant co...

用VB类实现文件对话框

用VB类实现文件对话框

用VB类实现文件对话框'类名:ComDlg.cls '作用:文件打开保存对话框 ' ' ' 'By:Apull '2007-5-21 'http://www.apull.net Option Explicit Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" ( _ pOpenfil...

常用asp函数

常用asp函数

<% '------------------------------------- '所有功能函数名如下: ' StrLength(str) 取得字符串长度 ' CutStr(str,strlen) 字符串长度切割 ' CheckIsEmpty(tstr) 检测是否为空 ' isInteger(para) 整数检验 ' CheckName(str) 名字字符校验 ' CheckPassword(str) 密码检验 ' CheckEmail(emai...

SetTimer(), KillTimer() 使用

SetTimer(), KillTimer() 使用

SetTimer函数的用法  1 )用WM_TIMER来设置定时器  先请看SetTimer这个API函数的原型  UINT_PTR SetTimer(   HWND hWnd, // 窗口句柄   UINT_PTR nIDEvent, // 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器   UINT uElapse, // 时间间隔,单位为毫秒   TIMERPROC lpTimerFunc // 回调函数   );例如  SetTimer...