如何在windowsphone中实现照片选择功能
本文关键字:照片 选择 功能 实现 windowsphone | 更新日期: 2023-09-27 18:25:07
我正在开发一个应用程序,它需要从库中选择背景图像。为此,我正在实现与Windows phone 8.1
中的Choose Photo
功能相同的功能(设置背景图像),
我试过这个:
xaml:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Name="contentPanel">
<ScrollViewer Name="scrl" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Opacity="0.3">
</ScrollViewer>
<ScrollViewer Name="scrlView" Height="500" Width="300" BorderBrush="Red" BorderThickness="1" Background="Transparent">
</ScrollViewer>
<Image Name="mtpImg" Stretch="Fill" />
</Grid>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar Mode="Minimized">
<shell:ApplicationBarIconButton IconUri="Assets'ApplicationIcon.png" Click="gallery_click" Text="gallery"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
C#:
private void gallery_click(object sender, EventArgs e)
{
PhotoChooserTask chooser = new PhotoChooserTask();
chooser.Completed += gallery_Completed;
chooser.Show();
}
private void gallery_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
Image img = new Image();
BitmapImage tmpBitmap = new BitmapImage();
tmpBitmap.SetSource(e.ChosenPhoto);
img.Source = tmpBitmap;
scrl.Content = img;
}
}
问题:如何设置opacity=1
以在scrlView
ScrollViewer中显示图像?
尝试将不透明度设置为1:
private void gallery_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
Image img = new Image();
BitmapImage tmpBitmap = new BitmapImage();
tmpBitmap.SetSource(e.ChosenPhoto);
img.Source = tmpBitmap;
scrl.Content = img;
scrl.Opacity = 1.0;
}
}
如果你想在带有边框的图像控制中设置图像,你可以试试这个:
XAML:
<Grid Grid.Row="0" Name="contentPanel">
<Border BorderBrush="Red" Height="500" Width="300" BorderThickness="1">
<Image Name="mtpImg" Stretch="Fill" Height="500" Width="300"/>
</Border>
</Grid>
CS:
PhotoChooserTask chooser;
public TaskPage()
{
InitializeComponent();
chooser = new PhotoChooserTask();
chooser.Completed += gallery_Completed;
}
private void gallery_click(object sender, EventArgs e)
{
chooser.Show();
}
private void gallery_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage tmpBitmap = new BitmapImage();
tmpBitmap.SetSource(e.ChosenPhoto);
mtpImg.Source = tmpBitmap;
}
}