Avatar of Russ Suter
Russ Suter

asked on 

Winforms Drag & Drop image with transparency

I have the following code:
        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            Button btn = sender as Button;
            using (Bitmap bmp = new Bitmap(btn.Width, btn.Height))
            {
                btn.DrawToBitmap(bmp, new Rectangle(Point.Empty, btn.Size));
                using (Graphics gfx = Graphics.FromImage(bmp))
                {
                    ColorMatrix matrix = new ColorMatrix();
                    matrix.Matrix33 = .5F;
                    ImageAttributes attributes = new ImageAttributes();
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    gfx.DrawImage(bmp, new Rectangle(Point.Empty, bmp.Size));
                    Cursor cur = new Cursor(bmp.GetHicon());
                    Cursor.Current = cur;
                }
            }
        }

Open in new window

It's supposed to draw the image with transparency but it's opaque. How do I add alpha channel info? My ultimate goal is to have an alpha channel gradient so the transparency increases as the image gets further away from a given point (usually the center or the left edge).
C#.NET Programming

Avatar of undefined
Last Comment
Russ Suter
ASKER CERTIFIED SOLUTION
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Russ Suter
Russ Suter

ASKER

That's good enough for now. I'll look into the alpha gradient another time. Thanks.
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Glad it helped, you are welcome. Hope you have a nice long weekend.
Avatar of Russ Suter
Russ Suter

ASKER

More points in it for you if you can answer this question also:
https://www.experts-exchange.com/questions/28904561/DataGridView-get-current-row-rectangle.html
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo