开发者

Getting selected image of photo chooser task to image control C# Windows phone 7

开发者_开发问答

Trying to get the selected image from the photo chooser task into a image control. But I got an error of

"Cannot implicity convert type 'System.Windows.Media.ImageBrush' 
to 'System.Windows.Media.ImageSource'"

How should i go about doing it?

The code i used:

            var bitmapImage = new BitmapImage();
            base.OnNavigatedFrom(e);
            ImageBrush bgImage = new ImageBrush();
            bgImage.ImageSource = App.globalData.bitmapImage;
            image1.Source = bgImage; 


Basicall, the error is saying that you're trying to set your ImageSource of bgImage to an existing imagebrush.

Try changing your code to the following:

base.OnNavigatedFrom(e);
image1.Source = App.globalData.bitmapImage;

You're getting that error because you're trying to create a new brush and assign an existing imagebrush as it's imagesource property. Since you already have an imagebrush (App.globalData.bitmapImage) then you can just remove all the logic that has to do with creating the brush and assign it directly to the source of your image. (image1.Source = App.globalData.bitmapImage;)

P.S.

Here is some code that I use to get a photo from the photochooser task:

    private void PhotoChooserCompleted(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            var img = new BitmapImage();
            img.SetSource(e.ChosenPhoto);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜