-
Notifications
You must be signed in to change notification settings - Fork 222
Update Vanara.WinUI.Extensions build environment
#594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7ebb406
06c22df
5cd3c3c
cf1f44b
55185c2
a1b5d00
ec8fc59
779166b
64cdb30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used default values, i don't need em |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used default values, i don't need em |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used default values, i don't need em |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs updates and refactoring. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* DOCS: | ||
| * | ||
| * REFERENCES | ||
| * | ||
| * <seealso cref="tajbender.Vanara\Windows.Forms\Extensions\IconExtension.cs"/> | ||
| * | ||
| */ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Drawing; | ||
| using System.Linq; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Vanara.PInvoke; | ||
|
|
||
| namespace Vanara.WinUI.Extensions; | ||
|
|
||
| #region Properties | ||
| /// <summary>Used to determine the size of the icon returned by various shell methods.</summary> | ||
| public enum IconSize | ||
| { | ||
| /// <summary> | ||
| /// The image size is normally 32x32 pixels. However, if the Use large icons option is selected from the Effects section of the Appearance tab in | ||
| /// Display Properties, the image is 48x48 pixels. | ||
| /// </summary> | ||
| Large = Shell32.SHIL.SHIL_LARGE, | ||
| /// <summary>The image is the Shell standard small icon size of 16x16, but the size can be customized by the user.</summary> | ||
| Small = Shell32.SHIL.SHIL_SMALL, | ||
| /// <summary>The image is the Shell standard extra-large icon size. This is typically 48x48, but the size can be customized by the user.</summary> | ||
| ExtraLarge = Shell32.SHIL.SHIL_EXTRALARGE, | ||
| /// <summary>Windows Vista and later. The image is normally 256x256 pixels.</summary> | ||
| Jumbo = Shell32.SHIL.SHIL_JUMBO | ||
| } | ||
| #endregion | ||
|
|
||
| #region Embedded classes | ||
| public record SoftwareBitmapSource | ||
| { | ||
| public IconSize IconSize; | ||
|
|
||
| public SoftwareBitmapSource(IconSize iconSize) => IconSize = iconSize; | ||
|
|
||
| public static Task<SoftwareBitmapSource> FromIcon(Icon icon) | ||
| { | ||
| return IconExtension.GetWinUi3BitmapSourceFromIcon(icon); | ||
| } | ||
| } | ||
| #endregion | ||
|
|
||
| /// <summary>Extension methods for <see cref="Icon"/>. | ||
| /// This class replaces "Vanara.Windows.Forms.Extensions.IconExtension" for WinUI. | ||
| /// </summary> | ||
| public static class IconExtension | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| /// <param name="bitmapIcon"></param> | ||
| /// <param name="iconSize"></param> | ||
| /// <returns></returns> | ||
| public static async Task<SoftwareBitmapSource> GetWinUi3BitmapSourceFromIcon(Icon bitmapIcon, IconSize iconSize) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(bitmapIcon); | ||
|
|
||
| return await GetWinUi3BitmapSourceFromGdiBitmap(bitmapIcon.ToBitmap()); | ||
| } | ||
|
|
||
| /* TODO: add to https://github.com/tajbender/tajbender.Vanara/blob/master/WinUI.Extensions/ShellImageSource.cs */ | ||
|
|
||
| /// <summary> | ||
| /// Taken from <see href="https://stackoverflow.com/questions/76640972/convert-system-drawing-icon-to-microsoft-ui-xaml-imagesource"/> | ||
| /// See also <see href="https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imaging.bitmapimage?view=windows-app-sdk-1.6"/>, which can deal with .ico natively. | ||
| /// </summary> | ||
| /// <param name="bitmapIcon"></param> | ||
| /// <returns></returns> | ||
| public static async Task<SoftwareBitmapSource> GetWinUi3BitmapSourceFromIcon(Icon bitmapIcon) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(bitmapIcon); | ||
|
|
||
| return await GetWinUi3BitmapSourceFromGdiBitmap(bitmapIcon.ToBitmap()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Taken from <see href="https://stackoverflow.com/questions/76640972/convert-system-drawing-icon-to-microsoft-ui-xaml-imagesource"/>. | ||
| /// See also <see href="https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.image.source?view=windows-app-sdk-1.5#microsoft-ui-xaml-controls-image-source"/>. | ||
| /// See also <see href="https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imaging.bitmapimage?view=windows-app-sdk-1.6"/>, which can deal with .ico natively. | ||
| /// </summary> | ||
| /// <param name="gdiBitmap"></param> | ||
| /// <returns></returns> | ||
| public static async Task<SoftwareBitmapSource?> GetWinUi3BitmapSourceFromGdiBitmap(Bitmap gdiBitmap) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(gdiBitmap); | ||
|
|
||
| // get pixels as an array of bytes | ||
| var data = gdiBitmap.LockBits(new System.Drawing.Rectangle(0, 0, gdiBitmap.Width, gdiBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, gdiBitmap.PixelFormat); | ||
| var bytes = new byte[data.Stride * data.Height]; | ||
| Marshal.Copy(data.Scan0, bytes, 0, bytes.Length); | ||
| gdiBitmap.UnlockBits(data); | ||
|
|
||
| // get WinRT SoftwareBitmap | ||
| var softwareBitmap = new Windows.Graphics.Imaging.SoftwareBitmap( | ||
| Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, | ||
| gdiBitmap.Width, | ||
| gdiBitmap.Height, | ||
| Windows.Graphics.Imaging.BitmapAlphaMode.Premultiplied); | ||
| softwareBitmap.CopyFromBuffer(bytes.AsBuffer()); | ||
|
|
||
| // build WinUI3 SoftwareBitmapSource | ||
| var source = new SoftwareBitmapSource(); | ||
| await source.SetBitmapAsync(softwareBitmap); | ||
| return source; | ||
| } | ||
|
|
||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,21 @@ | ||
| ## Assembly report for Vanara.WinUI.Extensions.dll | ||
| Extension methods and conversions from Vanara P/Invoke types and methods to UWP and WinUI types and methods. | ||
| Extension methods and conversions from Vanara P/Invoke types and methods to WinUI types and methods. | ||
|
|
||
| _UWP-Compatible types and methods are included in the Vanara.UWP.Extensions assembly._ | ||
|
|
||
| ### Classes | ||
| Class | Description | ||
| ---- | ---- | ||
| [Vanara.PInvoke.SystemFoundationExtensions](https://github.com/dahall/Vanara/search?l=C%23&q=SystemFoundationExtensions) | Conversion extension methods for WinUI/UWP and Vanara types. | ||
| [Vanara.WinUI.Extensions.SystemFoundationExtensions](https://github.com/dahall/Vanara/search?l=C%23&q=SystemFoundationExtensions) | Conversion extension methods for WinUI3 and Vanara types. | ||
| [Vanara.WinUI.Extensions.SystemFoundationExtensions](https://github.com/dahall/Vanara/search?l=C%23&q=SystemFoundationExtensions) | Conversion extension methods for WinUI3 and Vanara types. | ||
|
|
||
| ### Namespaces | ||
| Namespace | Description | ||
| --------- | ----------- | ||
|
|
||
| ### **Vanara.WinUI.Extensions** | ||
|
|
||
|
|
||
| docs\icons\Vanara64x64.png | ||
|
|
||
| [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used default values, i don't need em