ComponentOne Bitmap for UWP
In This Topic
    Quick Start
    In This Topic

    The quick start guide familiarizes you with loading an image in Bitmap. You begin with creating a UWP application in Visual Studio, adding C1.UWP.Bitmap reference (dll), Image control, and a button to load an image from stream in C1Bitmap object.

    To create a simple UWP application for loading an image in C1Bitmap object, follow these steps:

    1. Setting up the Application
    2. Loading an Image into C1Bitmap

    The following image shows how the application displays an image loaded from a stream into C1Bitmap:

    Setting up the Application

    To set up the application, follow these steps:

    1. Create a new project and select Blank App (Universal Windows) in Visual Studio.
    2. Add the following references to the application.
      • C1.UWP.Bitmap
      • C1.UWP.DX
    3. In the Solution Explorer, right click your project name and select Add | New Folder. Name the newly added folder. In our case, we have named the new folder as Resources.
    4. Add a sample image to the Resources folder and set its Build Action property to Embedded Resource from the Properties window.
    5. Add a standard Button control for loading a sample image and Image control, named img, for displaying the sample image.
    6. Set the Content property of the button as Load Image.
    Back to Top

    Loading an Image into C1Bitmap

    To load the image in C1Bitmap, follow these steps:

    1. Switch to the code view and add the following import statements in the code.
      Imports C1.Xaml.Bitmap
      Imports System.Reflection
      Imports Windows.Graphics.Imaging
      using C1.Xaml.Bitmap;
      using System.Reflection;
      using System.Threading.Tasks;
      using Windows.Graphics.Imaging;
      using Windows.UI.Xaml.Media.Imaging;
    2. Create the following class objects.
      Dim btmp As C1Bitmap
      Dim sb As SoftwareBitmap
      Dim sbs As SoftwareBitmapSource
      C1Bitmap btmp;
      SoftwareBitmap sb;
      SoftwareBitmapSource sbs;
    3. Add the following code in the class constructor to initialize bitmap and SoftwareBitmapSource.
      btmp = New C1Bitmap()
      sbs = New SoftwareBitmapSource()
      btmp = new C1Bitmap();
      sbs = new SoftwareBitmapSource();
    4. Add the following code to the btnLoad_Click event to load the image in C1Bitmap using stream:
      Dim asm As Assembly = GetType(MainPage).GetTypeInfo().Assembly
      Using stream As Stream = asm.GetManifestResourceStream("BitmapUWP_VB.GrapeCity.jpg")
          btmp.Load(stream, New FormatConverter(PixelFormat.Format32bppPBGRA))
      End Using
      Await UpdateImageSource()
      Assembly asm = typeof(MainPage).GetTypeInfo().Assembly;
      using (Stream stream = asm.GetManifestResourceStream("BitmapUWP.Resources.GrapeCity.jpg"))
          btmp.Load(stream, new FormatConverter(PixelFormat.Format32bppPBGRA));
      await UpdateImageSource();
      Note: To call an asynchronous method on an event, we have used async keyword and await operator.
    5. Create a method, named UpdateImageSource, to create a SoftwareBitmap, set the source SoftwareBitmap and assign it to the image source:
      Private Async Function UpdateImageSource() As Task
          sb = btmp.ToSoftwareBitmap()
          Await sbs.SetBitmapAsync(sb)
          img.Source = sbs
      End Function
      private async Task UpdateImageSource()
          sb = btmp.ToSoftwareBitmap();
          await sbs.SetBitmapAsync(sb);
          img.Source = sbs;
    Back to Top
    See Also