zoukankan      html  css  js  c++  java
  • C# picturebox 加载图片后透明显示在另一控件之上

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Imaging;
    
    namespace WindowsFormsApplication5
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            public static void ChangeOpacity(PictureBox pb, Single opacity, Control parent)
            {
                var img = pb.Image;
                var bmp = new Bitmap(img.Width, img.Height);
                using (var g = Graphics.FromImage(bmp))
                {
                    var colorMatrix = new ColorMatrix();
                    colorMatrix.Matrix33 = opacity;
                    var attr = new ImageAttributes();
                    attr.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    g.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attr);
                }
                pb.BackColor = Color.Transparent;
                pb.Image = bmp;
                pb.Parent = parent;
                pb.Left = 0;
                pb.Top = 0;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                ChangeOpacity(pictureBox1, 0.3F, button1);
            }
        }
    }

    这个方法只能保证picturebox仅对其父控件透明
     
  • 相关阅读:
    感悟.学习的方式
    IOS地理信息使用
    IOSTimer的例子留个备注
    IOSSelector的用法
    ios中addtarget的用法
    ios绘图时的坐标处理
    mac下装Ruby
    iOSbase64
    ios跳转
    Misha and Palindrome Degree CodeForces
  • 原文地址:https://www.cnblogs.com/nanfei/p/10796366.html
Copyright © 2011-2022 走看看