• Stars
    star
    319
  • Rank 131,436 (Top 3 %)
  • Language
    C#
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add SVG's and PNG's to your shared Xamarin Project

Resizetizer NT (for Workgroups and fun individuals)

Take SVG's and PNG's and automagically have them resized to all the different resolutions and included in your Xamarin Android, iOS, UWP, and WPF projects!

NuGet

Blog Post: redth.codes/resizetizer-nt-shared-images-for-xamarin

Video:

Shared Images in Xamarin with Resizetizer NT

History

A few years back I created a thing I called Resizetizer which helped solve the pain of resizing images to every single target density/resolution for iOS, Android, and UWP.

The original incarnation required that you define a .yaml file with all of your inputs and desired outputs. If you referenced this yaml file in your project and built it, the images would all be resized according to your config. You also had to specify all the various resolutions you wanted to output in the config file.

NT (New Technology)

This was great, but we could do better yet! The Resizetizer NT (New Technology) improves the story in a few ways:

  1. Add your images to your shared (netstandard2) projects with the SharedImage build action
  2. The config file is no longer necessary (or even a thing at all)
  3. Ideal resolutions for each platform are automatically created
  4. Resized images are automatically included in your Xamarin iOS, Android and UWP app head projects

How to use it

First you need to add the ResizetizerNT NuGet package to your shared code (netstandard2.0) project, as well as your Xamarin iOS/Android/UWP app projects. It's important to install it in all of your projects for this to work.

Next, add the images to your shared code (netstandard2.0) project as SharedImage build actions:

<ItemGroup>
  <SharedImage 
    Include="hamburger.svg"
    BaseSize="40,20" />
</ItemGroup>

Or you can specify it for each project like this :

<ItemGroup Condition="$(_ResizetizerIsiOS) == 'True'">
  <SharedImage Include="image.svg" BaseSize="44,44" />
</ItemGroup>

<ItemGroup Condition="$(_ResizetizerIsAndroid) == 'True'">
  <SharedImage Include="image.svg" BaseSize="50,50" />
</ItemGroup>

<ItemGroup Condition="$(_ResizetizerIsUWP) == 'True'">
  <SharedImage Include="image.svg" BaseSize="55,55" />
</ItemGroup>

<ItemGroup Condition="$(_ResizetizerIsWPF) == 'True'">
  <SharedImage Include="image.svg" BaseSize="60,60" />
</ItemGroup>

These images can be .svg or .png types.

BaseSize

Notice the BaseSize attribute which you will need to manually add. This is required for the resizer to know the baseline or nominal, or original (whatever you want to call it) density size. This is the size you would use in your code to specify the image size (eg: <Image Source="hamburger.png" WidthRequest="40" HeightRequest="20" />). In Android this is the drawable-mdpi resolution, on iOS you can consider it the @1x resolution, and on UWP it's the scale-100 resolution.

Referencing the Resized Images

When you build your app projects, they will invoke a target in your shared code project to collect all of the SharedImage items to process. These items will all be resized and automatically included in your app project as the appropriate type for an image resource.

You can reference images just like you normally would. The important thing to note is that if your input image source is .svg, you will actually reference a .png in your app.

In Xamarin Forms you would use something like:

<Image Source="hamburger.png" WidthRequest="40" HeightRequest="20" />

TintColor

If you'd like to render your images with a tint, you can set the TintColor attribute property on the SharedImage element. This renders your image with a color filter of "Source In" in SkiaSharp. This is particularly useful in cases where you have icons or simple images you'd like to render in different color than the source.

Example: <Image Source="hamburger.png" TintColor="#66b3ff" />

Planning

Bitmaps

By default if no BaseSize attribute is specified on the SharedImage item, the image should not be resized at all and instead simply included as a standard image in the app head project (Resources/drawable on android, etc.). If an BaseSize is specified, then the resizing rules apply to the image and different copies of the image should be made for the various display densities of each app head project.

Vectors

Vectors provide the best results for resizing an image to the display densities of each device. By default if no BaseSize attribute is specified on the SharedImage item, the vector should not resized at all and is simply included as a standard vector image in the app head project (Resources/drawable on android, etc.).

On Android the vector should also be converted to a Vector Drawable format resource.

Since by its very nature a vector’s size is unknown, if it is to be resized, a BaseSize must be included to support resizing to different display densities. Resize rules apply here.

Resize Rules

When an image needs to be resized for various display densities we need to know it's baseline or standard 1.0 device display density scale or factor in order to derive other image sizes to resize for other densities.

For the purpose of adding images to a project this is being called the BaseSize, and is specified in the project’s SharedImage item.

When no BaseSize is specified, on android this maps to drawable-mdpi, on iOS this is the equivalent of @1x, and on UWP it is scale-100.

When an BaseSize is specified this is considered the 1.0 scale factor for the images. All other density sizes are derived from this.

The original size is typically the expected density independent pixel size you intend to use the image in. For example this is the size you would intend to set for the RequestedWidth and RequestedHeight of a Xamarin.Forms Image control.

There are some default densities depending on target platform:

Android

  • 1.0 drawable-mdpi
  • 1.5 drawable-hdpi
  • 2.0 drawable-xhdpi
  • 3.0 drawable-xxhdpi
  • 4.0 drawable-xxxhdpi

iOS

  • 1.0 @1x
  • 2.0 @2x
  • 3.0 @3x

UWP

  • 1.0 scale-100
  • 2.0 scale-200
  • 3.0 scale-300 ?
  • 4.0 scale-400 ?

WPF

  • 4.0

Not sure if 3.0 and 4.0 scales are used in UWP or common. Need to decide if we should generate these or not. Interestingly UWP also allows for high vs low contrast images. Might be something to think about down the road.

Other Platforms

Tizen? MacOS? WPF?

IDE Integration

The proposed solution does not require but may benefit from some IDE customization or integration.

Adding items to a csproj manually is becoming more normal in sdk style projects.

Project Intellisense

It appears to be possible for us to add to the visual studio XSD for generating Intellisense inside project files so that attributes like BaseSize will show up as possible options.

Property Editor

You can already add images to a project which default to be in the None item group. You will be able to select SharedImage as a build action. In addition it may be possible to add properties to the property editor for things like BaseSize to be accessible from the IDE UI.

Other Features

There is an opportunity with things like vectors to provide some other interesting features:

  • TintColor for vectors could look something like this, where all paths would be set to fill with the specified color: <SharedImage Include="my.svg" Size="10,10" TintColor="#123456" />
  • Optimize/Crunch output images (eg: pngcrunch)
    • iOS does this as a build step already don’t think android does, not sure if this fits into this step or if we should look at baking png optimization into android core build
  • Custom DPI outputs: This would be a power user feature which could allow the project item to specify the densities which will be generated for the image including the path and file suffix on a per platform basis, which might be helpful for things like app icons. This could look something like:
    <SharedImage Include="my.svg" Size="10,10">
      <!-- Maybe Apple and Android add 5.0 scale support before we do? -->
      <OutputSize Scale="5.0" PathPrefix="drawable-xxxxhdpi" />
      <OutputSize Scale="5.0" FileNamePostfix="@5x" />
    </SharedImage>
  • AppIcons - on iOS these are asset catalogs? Maybe there should be an attribute or a new build action specifically for app icons which generates mipmap drawables on android and asset catalogs on iOS since this is a pretty specific use case

Progress

Completed

  • Android msbuild targets are working correctly.
  • iOS msbuild targets are working correctly.
  • Image resizing
    • SVG→Bitmap scaling works with Skia.Svg
    • Bitmap→Bitmap scaling works with SkiaSharp

In Progress

  • Add TintColor support for SVG
  • Need to add svg→android vector processing support
  • UWP

More Repositories

1

PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
C#
4,362
star
2

ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
C#
1,067
star
3

dotnet-maui-check

.NET MAUI Check tool
C#
474
star
4

ZXing.Net.Maui

Barcode Scanning for MAUI?
C#
416
star
5

APNS-Sharp

Apple Push Notification & Feedback Services Client C# Library
C#
255
star
6

Maui.VirtualListView

A slim ListView implementation for .NET MAUI that uses Platform virtualized lists / collections
C#
226
star
7

FlamedTVLauncher

A replacement home launcher for Amazon FireTV
C#
189
star
8

HttpTwo

A basic C# HTTP/2 client library
JavaScript
117
star
9

Maui.UITesting

Experimenting with UI Testing approaches for .NET / MAUI
C#
103
star
10

MAUI.AppLinks.Sample

Sample .NET MAUI app which supports deep linking
C#
54
star
11

AndroidSdk.Tools

.NET Library + global tool for various Android SDK Manager, ADB, AVD, Emulator commands
C#
52
star
12

Microsoft.Maui.Platform.Channels

A simple bridge for messaging between .NET and iOS/MacCatalyst/Android Platforms at runtime
C#
51
star
13

Resizetizer

Easily automateable Image resizing for your Xamarin.iOS and Xamarin.Android app assets!
C#
47
star
14

MSSolutionLauncher

Launch multiple instances of Visual Studio for Mac and/or Xamarin Studio easily!
C#
46
star
15

FlatUI.Xamarin.Android

FlatUI Port for Xamarin.Android of CengaLabs FlatUI Kit by @eluleci
C#
46
star
16

C2DM-Sharp

C# Client and Server Libraries for Android C2DM (Cloud 2 Device Messaging)
C#
42
star
17

Xamarin.Binding.Helpers

MSBuild Tasks to help with Binding projects for Xamarin Android and iOS
C#
40
star
18

Android.Signature.Tool

Simple GUI tool for Mac and Windows to help find the SHA1 and MD5 hashes of your Android keystore's and apk's
C#
38
star
19

AppleDev.Tools

.NET Library with useful Apple/Xcode tool wrappers and implementations for developers
C#
37
star
20

MonoDroid.UrlImageViewHelper

C# / Mono for Android Port of koush's UrlImageViewHelper
C#
35
star
21

Xamarin.AppleSignIn.Sample

A sample of how to implement Apple Sign In in Xamarin.Forms for Android, iOS, and UWP
C#
32
star
22

WshLst

Wish List App for Xamarin Developer Showdown
C#
32
star
23

Microsoft.Maui.Icons

Simple project to extract glyphs from icon fonts and generate consts for their names and unicode values
C#
23
star
24

LogcatSharp

ADB Logcat viewer written in C# using Winforms
C#
22
star
25

GCMSharp

Google Cloud Messaging Client & Server Libraries ported to C#
C#
22
star
26

GCM.Client

[DEPRECATED] Add Google Cloud Messaging to your Xamarin.Android application
C#
22
star
27

PassKitSharp

C# / .NET Library for Reading and Writing PassKit files
C#
21
star
28

XamarinEncapsulateNativeSample

An example of how to encapsulate native SDK's with easy bindings to simple API's
C#
18
star
29

xf-to-maui

C#
16
star
30

Xamarin.AspNetCore.Authentication

Add authentication to your Xamarin apps using Asp.Net Core's built in authentication and providers
C#
15
star
31

JabbRIsMobile

MvvmCross based set of mobile apps for JabbR
C#
14
star
32

EggsToGo

Xamarin Cross Platform mobile library for implementing Easter Eggs!
C#
13
star
33

AppStoreConnectNet

.NET Client Library for Apple's AppStoreConnect API's
C#
12
star
34

Maui.Generators.Prototype

A playground with some conceptual generators that could be used in Maui / Single Project
C#
12
star
35

MonoTouch.UrlImageStore

A Url Image Store for Lazy Loading Images
C#
11
star
36

MavenNet

A C# Client for inspecting and interacting with Maven Repositories
C#
11
star
37

XamarinMultiWindowTesting

C#
11
star
38

Plugin.Maui.PoppedContentView

Simple popup control & service for .NET MAUI
C#
11
star
39

iOS.BackgroundFetch.Sample

Xamarin.iOS Recipe for implementing Background Fetching
C#
9
star
40

MonoDroid.UrlImageStore

A Url Image Store for Lazy Loading Images for MonoDroid
C#
9
star
41

Xamarin.AndroidBinderator

An engine to generate Xamarin Binding projects from Maven repositories with a JSON config and razor templates
C#
9
star
42

MauiExceptionsGottaCatchEmAll

Playing with exception handling in MAUI
C#
8
star
43

XamarinSingleProjectConcept

Working area for development a concept of what Single Projects could look like for Xamarin in net6
C#
8
star
44

NestSharp

A Portable NEST API Client for C#/.NET
C#
7
star
45

Google.Auth

Google OAuth Library for C#
C#
7
star
46

Svg2VectorDrawable.Net

C# port of Android Studio's Svg2Vector code
C#
7
star
47

Xamarin.Android.Xposed

Xamarin bindings for the Android Xposed client
C#
7
star
48

Plugin.SocialAuth

Xamarin Plugin to assist with Native social authentication
C#
6
star
49

XamarinStudio.RedthsAddin

Redth's Addins. Extensions for MonoDevelop/Xamarin Studio to improve productivity.
C#
6
star
50

MonoTouch.ImageGallery

Image Gallery View Controller
6
star
51

Xamarin.Wear.WatchFace

An Android Wear watch face made with Xamarin
C#
6
star
52

MAUI.Slim.Bindings

Examples of Slim binding patterns for use within .NET MAUI projects
5
star
53

MapboxSlimBindingDemo

Java
5
star
54

Wikitude.Xamarin

Xamarin.iOS and Xamarin.Android Bindings for Wikitude SDK
JavaScript
5
star
55

MavenRepoBrowser

Xamarin.Forms app for browsing a Maven Repo (Google's)
C#
4
star
56

GitHubReleaseNotesGenerator

A simple git/github based release notes generator
C#
4
star
57

Techorama-2014

My code, slides, etc. From Techorama 2014
C#
4
star
58

Talks

Objective-C
4
star
59

ZxingSharp.Mobile

Renamed to ZXing.Net.Mobile
4
star
60

Xamarin.ChromeCustomTabs

How to use Chrome Custom Tabs in your Xamarin.Android apps!
C#
4
star
61

UnitTests.HeadlessRunner

A platform agnostic netstandard20 unit test runner
C#
4
star
62

ImapiNet

IMAPI .NET Wrapper
C#
3
star
63

MauiIssueReproBrowser

C#
3
star
64

MauiAppCIPlayground

Just a place to play with building maui apps via CI
C#
3
star
65

PushSharp.ClientSamples

Xamarin Client Samples for registering for Push notifications
C#
3
star
66

PptxNotes

Easily export notes from a .pptx to .md and Import into your .pptx from .md
C#
3
star
67

MsiSneakAttack

List and remove those hard to clean .MSI installs!
C#
3
star
68

MauiCollectionViewGallery

Some usages of CollectionView in a MAUI app to test bugs / performance against
C#
3
star
69

dotNUT

.NET implementation of the NUT protocol
C#
3
star
70

Maui.GoogleMobileAds.iOS

iOS Bindings for Google's Mobile Ads SDK to use in .NET MAUI
C#
3
star
71

Maui.Onboarding

Docs, scripts, helpers, and more to configure your environment easily for .NET MAUI development
PowerShell
2
star
72

Xamarin.PlatformMessaging

C#
2
star
73

JdwpDotNet

JDWP (Java Debug Wire Protocol) Implementation in .NET
C#
2
star
74

FbSharp.MonoTouch.Authorization

MonoTouch Facebook Authorization Controller
2
star
75

Xamarin.CI

Simple code to test Continuous Integration
C#
2
star
76

NearbyMonkey

A sample app showing off the Nearby Messages API from Google
C#
2
star
77

Xamarin.PlatformMessaging.Sample

A Sample app using Platform Messaging features
C#
2
star
78

NuGetXamarinCompatibility

Test project to test Microsoft NuGet Packages (HTTP Client, BCL, BCL.Build) compatibility with Xamarin.Android, Xamarin.iOS, and Xamarin PCL projects
C#
2
star
79

Cake.Xamarin.Build

Cake addin for Xamarin product builds
C#
2
star
80

TwilioXamarinBindings

Twilio Bindings for Xamarin apps
C#
2
star
81

Xamarin.HttpClient.Repro

C#
2
star
82

Xappium.Maui.Playground

Just a repo to start testing Xappium UITesting with MAUI apps
C#
2
star
83

MauiEdgeToEdge

Playing around with edge to edge apps and safe areas
C#
2
star
84

FbSharp

C# Library for Facebook Graph API
1
star
85

Zxing

Zxing pull from subversion
1
star
86

f50

C#
1
star
87

GoogleSignInMigration

Sample Xamarin.iOS showing how to use the new Google SignIn API's with the old Plus API's
C#
1
star
88

redth.github.com

Redth
1
star
89

Plugin.Maui.Dev

A helpful package for .NET MAUI Plugin authors to make their dev experience more delightful
1
star
90

CvPlayground

Testing UICollectionView for learnings to apply to MAUI VirtualListView
C#
1
star
91

StreamDeck.Sp108e

Stream Deck Plugin for the SP108E WiFi LED Controller
HTML
1
star
92

homebridge-poolmath-automation

HomeBridge Plugin for PoolMath Automation Controller
TypeScript
1
star
93

CorsProxy

Simple CORS Proxy intended to help with development of WebAssembly apps
C#
1
star
94

AndroidSupportComponents

C#
1
star
95

xUnit.ResultWriter

Write xUnit v2 XML Result files without xUnit
C#
1
star
96

SingleAppEntryPointExperiments

C#
1
star
97

Cake.MonoApiTools

Mono API Tools (Info, Diff, HTML Diff)
C#
1
star
98

ZXing-bindings

MonoTouch bindings for the ZXing for iPhone
C#
1
star
99

VsCodeDotNetInterop

A nice example of using a dotnet exe from VSCode to invoke commands and return results
C#
1
star
100

try_git

1
star