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:
- Shows how to include a bitmap from the web
Classes:
Image
ImageSource
Program WebBitmapXaml
Page 286.
Concepts:
- 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:
- 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:
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:
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:
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:
- Shows an image browser.
Classes:
ActivityIndicator
Program BitmapStreams
Page 311
Concepts:
Shows how to stream bitmaps. (Note this is similar to the BlackCat program from Chapter 4.
Program DiyGradientBitmap
Page 315
Concepts:
- Shows how to create Bitmap gradients on the fly.
Classes:
.. Not as interested in this one. But primarily we are working with a built class called BmpMaker.
Program PlatformBitmaps
Page 315
Concepts:
- Shows how to use different bitmaps for different platforms.
- Talks about where the different images are stored in the different platforms.
Classes:
uses Device.OnPlatform
Program ImageTap
Page 315
Concepts:
Shows how to use GestureReconizer for tap events
Classes:
uses Device.OnPlatform
uses GestureRecognizer for tap events.
Program ToolbarDemo
Page 329
Concepts:
- Shows how to create a toolbar and to assign image icons to it.
Classes:
uses Device.OnPlatform
Program ButtonImages
Page 315
Concepts:
Shows how to add a small image onto a button (not a replacement for text see: ImageTap earlier in this chapter.
Classes:
uses Label