public async Task GetDrawableAsyncWithCustomFont() { var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts(fonts => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); }) .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.OfSize("Dokdo", 24), Color = Colors.Red, }; using var result = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(result.Value); var bitmap = bitmapDrawable.Bitmap; bitmap.AssertContainsColor(Colors.Red.ToPlatform()); }
public async Task GetDrawableAsync(string colorHex) { var expectedColor = Color.FromArgb(colorHex); var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts() .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.Default, Color = expectedColor, }; using var result = await service.GetDrawableAsync(imageSource, MauiProgram.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(result.Value); var bitmap = bitmapDrawable.Bitmap; bitmap.AssertContainsColor(expectedColor.ToPlatform()); }
public async Task GetImageAsync(string colorHex) { var expectedColor = Color.FromArgb(colorHex); var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts() .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.Default.WithSize(30), Color = expectedColor, }; using var drawable = await InvokeOnMainThreadAsync(() => service.GetImageAsync(imageSource)); var uiimage = Assert.IsType <UIImage>(drawable.Value); uiimage.AssertContainsColor(expectedColor.ToNative()); }
public async Task GetImageAsyncWithCustomFont() { var mauiApp = MauiApp.CreateBuilder() .ConfigureFonts(fonts => { fonts.AddFont("dokdo_regular.ttf", "Dokdo"); }) .ConfigureImageSources() .Build(); var images = mauiApp.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.OfSize("Dokdo", 24), Color = Colors.Red, }; using var drawable = await InvokeOnMainThreadAsync(() => service.GetImageAsync(imageSource)); var uiimage = Assert.IsType <UIImage>(drawable.Value); uiimage.AssertContainsColor(Colors.Red.ToNative()); }
public async Task GetDrawableAsync(string colorHex) { var expectedColor = Color.FromHex(colorHex); var host = new AppHostBuilder() .ConfigureFonts() .ConfigureImageSources() .Build(); var images = host.Services.GetRequiredService <IImageSourceServiceProvider>(); var service = images.GetRequiredImageSourceService <FontImageSourceStub>(); var imageSource = new FontImageSourceStub { Glyph = "X", Font = Font.Default, Color = expectedColor, }; using var drawable = await service.GetDrawableAsync(imageSource, Platform.DefaultContext); var bitmapDrawable = Assert.IsType <BitmapDrawable>(drawable.Value); var bitmap = bitmapDrawable.Bitmap; bitmap.AssertContainsColor(expectedColor.ToNative()); }