【问题标题】:want to Upload Image in the background of Ellipse through C#想通过C#在Ellipse的后台上传图片
【发布时间】:2017-08-11 07:34:54
【问题描述】:

我的 XAML 代码如下所示

<StackPanel Orientation="Vertical">
            <Ellipse x:Name="dp" Height="250" Width="250" Margin="0,10,0,0">
                <Ellipse.Fill>
                    <ImageBrush ImageSource="Assets/img.jpg"/>
                </Ellipse.Fill>
            </Ellipse>
            <Button Content="Upload Image" Margin="236,0,0,0" Click="Button_Click"/>
        </StackPanel>

&想要通过单击按钮更改背景图像(“上传图像”) & 这是我在 C# 中的后端编码

FileOpenPicker fop = new FileOpenPicker();
        fop.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        fop.FileTypeFilter.Add(".jpg");
        fop.FileTypeFilter.Add(".jpeg");
        StorageFile file = await fop.PickSingleFileAsync();
        IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
        if (file!=null)
        {
            BitmapImage bmp = new BitmapImage(new Uri(stream.));
            ImageBrush brush = new ImageBrush();
            brush.ImageSource = bmp;
        }

我是窗口应用程序的初学者

【问题讨论】:

    标签: c# windows xaml


    【解决方案1】:

    你尝试设置椭圆的填充,如果获取文件的代码工作正常,那么你应该能够做到这一点

     dp.Fill = brush;
    

    你还有错别字

    BitmapImage bmp = new BitmapImage(new Uri(stream.)); extra . after stream
    BitmapImage bmp = new BitmapImage(new Uri(stream));
    

    【讨论】:

    • 是的,它工作我只需添加“bmp.SetSource(stream);”这条线在上述情况下......非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多