Browse Source
[Win32] Fix LoadIcon (#13466)
* [Win32] Fix LoadIcon
* Add check for seekable stream
pull/13489/head
Benedikt Stebner
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
26 additions and
5 deletions
-
src/Windows/Avalonia.Win32/Win32Platform.cs
|
|
|
@ -239,18 +239,39 @@ namespace Avalonia.Win32 |
|
|
|
using (var memoryStream = new MemoryStream()) |
|
|
|
{ |
|
|
|
bitmap.Save(memoryStream); |
|
|
|
|
|
|
|
var iconData = memoryStream.ToArray(); |
|
|
|
|
|
|
|
return new IconImpl(new Win32Icon(iconData), iconData); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static IconImpl CreateIconImpl(Stream stream) |
|
|
|
{ |
|
|
|
var ms = new MemoryStream(); |
|
|
|
stream.CopyTo(ms); |
|
|
|
ms.Position = 0; |
|
|
|
var iconData = ms.ToArray(); |
|
|
|
return new IconImpl(new Win32Icon(iconData), iconData); |
|
|
|
if (stream.CanSeek) |
|
|
|
{ |
|
|
|
stream.Position = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (stream is MemoryStream memoryStream) |
|
|
|
{ |
|
|
|
var iconData = memoryStream.ToArray(); |
|
|
|
|
|
|
|
return new IconImpl(new Win32Icon(iconData), iconData); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
using (var ms = new MemoryStream()) |
|
|
|
{ |
|
|
|
stream.CopyTo(ms); |
|
|
|
|
|
|
|
ms.Position = 0; |
|
|
|
|
|
|
|
var iconData = ms.ToArray(); |
|
|
|
|
|
|
|
return new IconImpl(new Win32Icon(iconData), iconData); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void SetDpiAwareness() |
|
|
|
|