【问题标题】:how to implement choose photo feature in windows phone如何在 windows phone 中实现选择照片功能
【发布时间】:2014-10-01 14:57:16
【问题描述】:

我正在开发一个应用程序,它需要从图库中选择背景图片。为此,我正在实现与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 中显示图像?

【问题讨论】:

    标签: c# xaml windows-phone-8 windows-phone-8.1 scrollviewer


    【解决方案1】:

    尝试将不透明度设置为 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;
        }
    }
    

    【讨论】:

    • 这种方式为整个图像设置 opacity=1。我需要的是 opacity=1 用于框架内可见的图像部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多