Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
glennawatson committed Sep 20, 2019
1 parent 6c87509 commit ec7adf7
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions README.md
Expand Up @@ -50,44 +50,11 @@ Splat currently supports:
* Xamarin (Android, iOS and Mac)
* .NET Standard 1.0 and 2.0

## Cross-platform Image Loading

```cs
//
// Load an Image
// This code even works in a Portable Library
//
var wc = new WebClient();
byte[] imageBytes = await wc.DownloadDataTaskAsync("http://octodex.github.com/images/Professortocat_v2.png");

// IBitmap is a type that provides basic image information such as dimensions
IBitmap profileImage = await BitmapLoader.Current.Load(imageBytes, null /* Use original width */, null /* Use original height */);
```

Then later, in your View:

```cs
// ToNative always converts an IBitmap into the type that the platform
// uses, such as UIBitmap on iOS or BitmapSource in WPF
ImageView.Source = ViewModel.ProfileImage.ToNative();
```

Images can also be loaded from a Resource. On Android, this can either be a
Resource ID casted to a string, or the name of the resource *as* as string
(optionally including the extension).

```cs
var profileImage = await BitmapLoader.Current.LoadFromResource("DefaultAvatar.png", null, null);
```

Bitmaps can also be created and saved - actually *drawing* on the image is
beyond the scope of this library, you should do this in your view-specific
code.
## Detecting whether you're in a unit test runner

```cs
var blankImage = BitmapLoader.Current.Create(512.0f, 512.0f);
await blankImage.Save(CompressedBitmapFormat.Png, 0.0, File.Open("ItsBlank.png"));
// If true, we are running unit tests
ModeDetector.InUnitTestRunner();
```

## Service Location
Expand Down Expand Up @@ -262,7 +229,17 @@ Locator.CurrentMutable.UseSerilogFullLogger()

Thanks to @joelweiss for first creating this logger.

## Using Cross-Platform Colors and Geometry
## Cross platform drawing

| Target | Package | NuGet |
|---------|-------|------|
| Splat.Drawing | [Splat.Drawing][SplatDrawingNuGet] | [![SplatDrawingBadge]][SplatDrawingNuGet] |

[SplatDrawingNuGet]: https://www.nuget.org/packages/Splat.Drawing/
[SplatDrawingBadge]: https://img.shields.io/nuget/v/Splat.Drawing.svg

### Using Cross-Platform Colors and Geometry


```cs
// This System.Drawing class works, even on WinRT or WP8 where it's not supposed to exist
Expand Down Expand Up @@ -294,15 +271,49 @@ UIColor bgColor = ViewModel.BackgroundColor.ToNative();
// From an Android project
Android.Graphics.Color bgColor = ViewModel.BackgroundColor.ToNative();
```
### Cross-platform Image Loading

## Detecting whether you're in a unit test runner
```cs
//
// Load an Image
// This code even works in a Portable Library
//
var wc = new WebClient();
byte[] imageBytes = await wc.DownloadDataTaskAsync("http://octodex.github.com/images/Professortocat_v2.png");

// IBitmap is a type that provides basic image information such as dimensions
IBitmap profileImage = await BitmapLoader.Current.Load(imageBytes, null /* Use original width */, null /* Use original height */);
```

Then later, in your View:

```cs
// If true, we are running unit tests
ModeDetector.InUnitTestRunner();
// ToNative always converts an IBitmap into the type that the platform
// uses, such as UIBitmap on iOS or BitmapSource in WPF
ImageView.Source = ViewModel.ProfileImage.ToNative();
```

Images can also be loaded from a Resource. On Android, this can either be a
Resource ID casted to a string, or the name of the resource *as* as string
(optionally including the extension).

```cs
var profileImage = await BitmapLoader.Current.LoadFromResource("DefaultAvatar.png", null, null);
```

Bitmaps can also be created and saved - actually *drawing* on the image is
beyond the scope of this library, you should do this in your view-specific
code.

```cs
var blankImage = BitmapLoader.Current.Create(512.0f, 512.0f);
await blankImage.Save(CompressedBitmapFormat.Png, 0.0, File.Open("ItsBlank.png"));
```
### Detecting if you're in design mode

// If true, we are running inside Blend, so don't do anything
ModeDetector.InDesignMode();
PlatformModeDetector.InDesignMode();
```
## Contribute
Expand Down

0 comments on commit ec7adf7

Please sign in to comment.