XAMLの定義
XAMLエディタまたはBlendで定義するXAMLの内容は、次のようになります。
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:CZ1401ImagingVB" xmlns:common="using:CZ1401ImagingVB.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:custom="using:Leadtools.Controls" xmlns:Converter="using:CZ1401ImagingVB.Converter" x:Name="pageRoot" x:Class="CZ1401ImagingVB.MainPage" mc:Ignorable="d"> <Page.BottomAppBar> <CommandBar> <AppBarButton Label="画像指定" Icon="OpenFile" Command="{Binding OpenCommand}"/> </CommandBar> </Page.BottomAppBar> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.ChildrenTransitions> <TransitionCollection> <EntranceThemeTransition/> </TransitionCollection> </Grid.ChildrenTransitions> <Grid.RowDefinitions> <RowDefinition Height="140"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}" Style="{StaticResource NavigationBackButtonNormalStyle}" VerticalAlignment="Top" AutomationProperties.Name="Back" AutomationProperties.AutomationId="BackButton" AutomationProperties.ItemType="Navigation Button"/> <TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/> </Grid> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Image Grid.Column="0" Stretch="None" Source="{Binding ImageElement}"/> <custom:RasterImageViewer Grid.Column="1" Image="{Binding RasterElement}"/> </Grid> </Grid> </Page>
LEADTOOLSのコンポーネントは、Imageプロパティに表示したい画像データをBindingしているだけで特に何もプロパティを指定していません。
LEADTOOLSでの読み込みロジックの記述(PictureModel)
Public Class PictureModel Implements INotifyPropertyChanged Private _ImageElement As ImageSource = Nothing Public Property ImageElement As ImageSource Get Return Me._ImageElement End Get Set(value As ImageSource) Me._ImageElement = value OnPropertyChanged() End Set End Property Private _RasterElement As Leadtools.RasterImage Public Property RasterElement As Leadtools.RasterImage ' …① Get Return Me._RasterElement End Get Set(value As Leadtools.RasterImage) Me._RasterElement = value OnPropertyChanged() End Set End Property Public Async Function Open() As Task Dim picker = New Pickers.FileOpenPicker With { ' …② .ViewMode = Pickers.PickerViewMode.Thumbnail, .SuggestedStartLocation = Pickers.PickerLocationId.PicturesLibrary } picker.FileTypeFilter.Clear() picker.FileTypeFilter.Add(".jpg") picker.FileTypeFilter.Add(".png") picker.FileTypeFilter.Add(".tif") Dim file As StorageFile = Await picker.PickSingleFileAsync() ' …③ If file IsNot Nothing Then Using fileStream = Await file.OpenAsync(FileAccessMode.Read) Dim bitmap = New Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap.SetSource(fileStream) Me.ImageElement = bitmap End Using Dim leadStream As Leadtools.ILeadStream = Leadtools.LeadStreamFactory.Create(file) Using disposable As IDisposable = TryCast(leadStream, IDisposable) Using codecs As New Leadtools.Codecs.RasterCodecs Dim workImage = Await codecs.LoadAsync(leadStream) Me.RasterElement = workImage ' …④ End Using End Using End If End Function Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) _ Implements INotifyPropertyChanged.PropertyChanged Private Sub OnPropertyChanged(<CallerMemberName> Optional propertyName As String = Nothing) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) End Sub End Class
- ①LEADTOOLSのラスターイメージを格納するパブリックプロパティを定義
- ②画像ライブラリを開くためのFileOpenPickerを定義
- ③FileOpenPickerを実行
- ④指定された画像から作成したラスターイメージをパブリックプロパティに設定