[codex] Fix PNG IconSource conversion#232
Conversation
Code ReviewThis PR correctly addresses issue #208 where raw PNG streams were passed directly to What works well
Issues to address1. Width/Height overflow for images > 255 px (medium)In outStream.WriteByte((byte)metadata.Width); // silently wraps on > 255
outStream.WriteByte((byte)metadata.Height);The ICO directory entry encodes width/height as a single byte where 0 means 256. For any image wider or taller than 255 px the cast wraps silently:
Windows typically uses the embedded PNG dimensions rather than the directory-entry fields when rendering, so many cases will still render correctly — but tools that strictly parse the header will mis-report dimensions. Consider using 0 for the "256" special case: outStream.WriteByte(metadata.Width >= 256 ? (byte)0 : (byte)metadata.Width);
outStream.WriteByte(metadata.Height >= 256 ? (byte)0 : (byte)metadata.Height);2. Stream position not reset (low, but defensive)
if (stream.CanSeek)
stream.Position = 0;3.
|
Summary
System.Drawing.IconIconSourcepaths through the shared stream helperWhy
TaskbarIcon.OnIconSourceChangedusesToIconAsync(), which previously passed raw PNG streams intoSystem.Drawing.Icon. That works for.icocontent but throws forBitmapImagesources backed by PNG files, which is the failure reported in #208.Validation
dotnet build src/libs/H.NotifyIcon/H.NotifyIcon.csproj --configuration Release /p:GeneratePackageOnBuild=falsedotnet build src/libs/H.NotifyIcon.Wpf/H.NotifyIcon.Wpf.csproj --configuration Release /p:GeneratePackageOnBuild=falseFixes #208