Chapter 13 Notes

Title: Bitmaps

Summary

So much ado about Bitmaps. Twelve programs in all

Programming Concepts Summary

Concept

Page

Image

P. 283

Programs

Program WebBitmapCode

Page 284.

Concepts:

  1. Shows how to include a bitmap from the web

Classes:

  1. Image

  2. ImageSource

Program WebBitmapXaml

Page 286.

Concepts:

  1. Shows how to include a bitmap from the web using Xaml

Xaml:

<Image>
  <Image.Source>
    <UriImageSource Uri="https://developer.xamarin.com/demo/IMG_3256.JPG" Aspect="[AspectFit|Fill|AspectFill]" />
  </Image.Source>
</Image>

Program ResourceBitmapCode

Page 289

Concepts:

  1. Shows how to include a bitmap from an embedded resource (i.e. file)

   1 public class ResourceBitmapCodePage : ContentPage
   2 {
   3    public ResourceBitmapCodePage()
   4    {
   5      Content = new Image
   6      {
   7         Source = ImageSource.FromResource(
   8           "ResourceBitmapCode.Images.ModernUserInterface256.jpg"),
   9           VerticalOptions = LayoutOptions.Center,
  10           HorizontalOptions = LayoutOptions.Center
  11      };
  12   }
  13 }

Program StackedBitmap

Page 291

Concepts:

  1. Shows how to include a bitmap from an embedded resource (i.e. file) using XAML and a markup extension which is necessary!

Here is the markup extension:

   1 namespace StackedBitmap
   2 {
   3   [ContentProperty ("Source")]
   4   public class ImageResourceExtension : IMarkupExtension
   5   {
   6     public string Source { get; set; }
   7     public object ProvideValue (IServiceProvider serviceProvider)
   8     {
   9       if (Source == null)
  10       return null;
  11       return ImageSource.FromResource(Source);
  12     }
  13   }
  14 }

and here is the Xaml that uses it:

<Image Source="{local:ImageResource StackedBitmap.Images.Sculpture_320x240.jpg}"
  BackgroundColor="Aqua"
  SizeChanged="OnImageSizeChanged" />

Note:

Windows uses device independent units, but iOS and Android use pixels. "This inconsistency between the Windows Runtime and the other two platforms is actually beneficial when you’re accessing bitmaps from the individual platform projects. As you’ll see, iOS and Android include a feature that lets you supply different sizes of bitmaps for different device resolutions. In effect, this allows you to specify bitmap sizes in device-independent units, which means that Windows devices are consistent with those schemes." p 294.

Program DeviceIndBitmapSize

Page 301

Concepts:

  1. Shows how to include a bitmap and size it in dips as opposed to pixels using WidthRequest and HeightRequest.

No new Classes.

Program MadTeaParty

Page 303

Concepts:

  1. Shows how to use styles to set the WidthRequest property to a value corresponding to 1.5 inches or 240 dips.

No new classes.

Program ImageBrowser

Page 303

Concepts:

  1. Shows an image browser.

Classes:

  1. ActivityIndicator

Program BitmapStreams

Page 311

Concepts:

  1. Shows how to stream bitmaps. (Note this is similar to the BlackCat program from Chapter 4.

Program DiyGradientBitmap

Page 315

Concepts:

  1. Shows how to create Bitmap gradients on the fly.

Classes:

Program PlatformBitmaps

Page 315

Concepts:

  1. Shows how to use different bitmaps for different platforms.
  2. Talks about where the different images are stored in the different platforms.

Classes:

  1. uses Device.OnPlatform

Program ImageTap

Page 315

Concepts:

  1. Shows how to use GestureReconizer for tap events

Classes:

  1. uses Device.OnPlatform

  2. uses GestureRecognizer for tap events.

Program ToolbarDemo

Page 329

Concepts:

  1. Shows how to create a toolbar and to assign image icons to it.

Classes:

  1. uses Device.OnPlatform

Program ButtonImages

Page 315

Concepts:

  1. Shows how to add a small image onto a button (not a replacement for text see: ImageTap earlier in this chapter.

Classes:

  1. uses Label

ManagingAndProgrammingMobileApplications/Xamarin/Chapter 13 (last edited 2016-10-05 21:21:42 by scot)