Image loading on Windows. (#356)
This commit is contained in:
Родитель
18c0627ae6
Коммит
a6df2c396a
|
@ -2,6 +2,8 @@
|
|||
using IImage = Microsoft.Maui.Graphics.IImage;
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
using Microsoft.Maui.Graphics.Platform;
|
||||
#elif WINDOWS
|
||||
using Microsoft.Maui.Graphics.Win2D;
|
||||
#endif
|
||||
|
||||
namespace GraphicsViewDemos.Drawables
|
||||
|
@ -10,13 +12,16 @@ namespace GraphicsViewDemos.Drawables
|
|||
{
|
||||
public void Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
IImage image;
|
||||
Assembly assembly = GetType().GetTypeInfo().Assembly;
|
||||
using (Stream stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png"))
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
// PlatformImage isn't currently supported on Windows.
|
||||
image = PlatformImage.FromStream(stream);
|
||||
#elif WINDOWS
|
||||
image = new W2DImageLoadingService().FromStream(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
//if (image != null)
|
||||
|
@ -34,7 +39,6 @@ namespace GraphicsViewDemos.Drawables
|
|||
canvas.SetFillImage(image.Downsize(100));
|
||||
canvas.FillRectangle(0, 0, 240, 300);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#if IOS || ANDROID || MACCATALYST
|
||||
using Microsoft.Maui.Graphics.Platform;
|
||||
#elif WINDOWS
|
||||
using Microsoft.Maui.Graphics.Win2D;
|
||||
using System.IO;
|
||||
#endif
|
||||
using System.Reflection;
|
||||
using IImage = Microsoft.Maui.Graphics.IImage;
|
||||
|
@ -10,20 +13,22 @@ namespace GraphicsViewDemos.Drawables
|
|||
{
|
||||
public void Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
IImage image;
|
||||
Assembly assembly = GetType().GetTypeInfo().Assembly;
|
||||
using (Stream stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png"))
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
// PlatformImage isn't currently supported on Windows.
|
||||
image = PlatformImage.FromStream(stream);
|
||||
#elif WINDOWS
|
||||
image = new W2DImageLoadingService().FromStream(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (image != null)
|
||||
{
|
||||
canvas.DrawImage(image, 10, 10, image.Width, image.Height);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,13 +36,16 @@ namespace GraphicsViewDemos.Drawables
|
|||
{
|
||||
public void Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
//#if IOS || ANDROID || MACCATALYST
|
||||
// IImage image;
|
||||
// Assembly assembly = GetType().GetTypeInfo().Assembly;
|
||||
// using (Stream stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png"))
|
||||
// {
|
||||
//#if IOS || ANDROID || MACCATALYST
|
||||
// // PlatformImage isn't currently supported on Windows.
|
||||
// image = PlatformImage.FromStream(stream);
|
||||
//#elif WINDOWS
|
||||
// image = new W2DImageLoadingService().FromStream(stream);
|
||||
//#endif
|
||||
// }
|
||||
|
||||
// if (image != null)
|
||||
|
@ -45,7 +53,6 @@ namespace GraphicsViewDemos.Drawables
|
|||
// IImage newImage = image.Resize(100, 60, ResizeMode.Stretch, true);
|
||||
// canvas.DrawImage(newImage, 10, 10, newImage.Width, newImage.Height);
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,13 +60,16 @@ namespace GraphicsViewDemos.Drawables
|
|||
{
|
||||
public void Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
IImage image;
|
||||
Assembly assembly = GetType().GetTypeInfo().Assembly;
|
||||
using (Stream stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png"))
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
// PlatformImage isn't currently supported on Windows.
|
||||
image = PlatformImage.FromStream(stream);
|
||||
#elif WINDOWS
|
||||
image = new W2DImageLoadingService().FromStream(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (image != null)
|
||||
|
@ -67,7 +77,6 @@ namespace GraphicsViewDemos.Drawables
|
|||
IImage newImage = image.Downsize(100, true);
|
||||
canvas.DrawImage(newImage, 10, 10, newImage.Width, newImage.Height);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +84,16 @@ namespace GraphicsViewDemos.Drawables
|
|||
{
|
||||
public void Draw(ICanvas canvas, RectF dirtyRect)
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
IImage image;
|
||||
Assembly assembly = GetType().GetTypeInfo().Assembly;
|
||||
using (Stream stream = assembly.GetManifestResourceStream("GraphicsViewDemos.Resources.Images.dotnet_bot.png"))
|
||||
{
|
||||
#if IOS || ANDROID || MACCATALYST
|
||||
// PlatformImage isn't currently supported on Windows.
|
||||
image = PlatformImage.FromStream(stream);
|
||||
#elif WINDOWS
|
||||
image = new W2DImageLoadingService().FromStream(stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Save image to a memory stream
|
||||
|
@ -94,7 +106,6 @@ namespace GraphicsViewDemos.Drawables
|
|||
}
|
||||
canvas.DrawImage(newImage, 10, 10, newImage.Width, newImage.Height);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче