dotnet / dotnet/winforms

`Cursor.Draw` draws with broken alpha channel

Open
#10,360 14 comments 0 reactions 1 assignee Claimed by @JeremyKuhne View on GitHub
api-suggestion area-System.Drawing
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .NET version

7.0.400

### Did it work in .NET Framework?

No

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

_No response_

### Issue description

`Curosor.Draw` draws with broken alpha channel:
Result:
![image](https://github.com/dotnet/winforms/assets/1285934/727ae1e1-a75f-44fd-95bd-257b97ae75dc)
Expected:
![image](https://github.com/dotnet/winforms/assets/1285934/d4cd08e0-79b5-4ba3-95b5-942993deddec)

Also reported here more that 10 years ago: https://stackoverflow.com/questions/4451839/how-to-render-a-transparent-cursor-to-bitmap-preserving-alpha-channel

### Steps to reproduce

```cs
Cursor cursor = Cursors.AppStarting;
Bitmap bitmap = new Bitmap(cursor.Size.Width, cursor.Size.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
cursor.Draw(g, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.Save(Path.Combine(Directory.GetCurrentDirectory(), "cursor.png"), ImageFormat.Png);
```

This code with `Icon.FromHandle` and `Icon.ToBitmap` works as expected:
```cs
Cursor cursor = Cursors.AppStarting;
Icon icon = Icon.FromHandle(cursor.Handle);
Bitmap bitmap = icon.ToBitmap();
bitmap.Save(Path.Combine(Directory.GetCurrentDirectory(), "icon.png"), ImageFormat.Png);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.