Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

[UWP]Plugins PictureChooser PluginLoader can`t load #143

Closed
farlop opened this issue Nov 4, 2016 · 15 comments
Closed

[UWP]Plugins PictureChooser PluginLoader can`t load #143

farlop opened this issue Nov 4, 2016 · 15 comments

Comments

@farlop
Copy link

farlop commented Nov 4, 2016

Some time ago an UWP PictureChooser issue was asked to be created in this repository for follow up, but I've found no further reference in here

MvvmCross/MvvmCross#1258

Today I was trying with version 4.4 and same error happened to me

@Cheesebaron
Copy link
Member

You need to add bootstrap file for it manually.

@farlop
Copy link
Author

farlop commented Nov 4, 2016

I've already done that. After adding the bootstrap file:

using MvvmCross.Platform.Plugins;

namespace XamarinFormsCross2.UWP.Bootstrap
{
    public class PictureChooserPluginBootstrap
        : MvxPluginBootstrapAction<MvvmCross.Plugins.PictureChooser.PluginLoader>
    { }
}

On launching I've got an MvxException at setup.Initialize() with message: could not load plugin assembly for type MvvmCross.Plugins.PictureChooser.PluginLoader.

I've checked that project has reference to MvvmCross.Plugin.PictureChooser assembly and that on bin\x64\Debug the MvvmCross.Plugins.PictureChooser.dll and MvvmCross.Plugins.PictureChooer.WindowsStore.dll are present.

@Cheesebaron
Copy link
Member

I see the problem it looks for WindowsUWP and WindowsCommon, but it is the WindowsStore dll that is added to the project.

@farlop
Copy link
Author

farlop commented Nov 4, 2016

I supposed that, but I haven't found any version of the dll for UWP in the package. Platform targets for the package does not include 'uap10.0', which is found in other plugins (SQLitePCL for example).

@Cheesebaron
Copy link
Member

Let me see if I can cook it up for WindowsUWP, otherwise if you want to have a stab at it feel welcome to do so.

@eshy
Copy link

eshy commented Nov 4, 2016

The plugin has a WindowsStore dll which I think works fine in UWP projects if you override CreatePluginManager and add the .WindowsStore dll postfix. Is there a reason not to always search for WindowsStore if WindowsUWP or WindowsCommon don't exist?

@Cheesebaron
Copy link
Member

I don't think it is correct to always dump win8.1 into UWP projects? What happens if you run that on a phone? Wouldn't it expect wpa8.1 in that case?

@eshy
Copy link

eshy commented Nov 4, 2016

I guess so, I haven't actually tried it...

@Cheesebaron
Copy link
Member

https://github.com/MvvmCross/MvvmCross-Plugins/tree/picturechooser_uwp

I've added an UWP implementation. It is just linking in the Store version as the API seems to be the same.

I don't have a Windows Phone around so can't test on that.

@Cheesebaron
Copy link
Member

You can try this nuget locally and see if it works for you.

MvvmCross.Plugin.PictureChooser.4.4.1.nupkg.zip

@Cheesebaron Cheesebaron self-assigned this Nov 4, 2016
@farlop
Copy link
Author

farlop commented Nov 5, 2016

I've tried on my W10M and now it doesn't throw any exception, the camera launches and the picture is taken and confirmed! But when I want to bind it to a Image control in the View it looks awkward. Please find it in the attached file.

wp_ss_20161105_0001

The code used is this (Xamarin Forms):

MvxCommand _photo2Command;
        public ICommand Photo2Command
        {
            get


            {
                return _photo2Command ?? (_photo2Command = new MvxCommand(async () =>
                {
                    var task = Mvx.Resolve<IMvxPictureChooserTask>();
                    var photo = await task.TakePictureAsync(500, 90);

                    if (photo == null)
                        return;

                    Photo = ImageSource.FromStream(() => photo);

                }));
            }
        }

@Cheesebaron
Copy link
Member

Cheesebaron commented Nov 5, 2016

What is Photo and what is ImageSource?

I've only tried with a picture from the file picker which worked.

@farlop
Copy link
Author

farlop commented Nov 5, 2016

Photo is a Xamarin.Forms.ImageSource that I use for binding with the view. Let me show you the full relevant code for the ViewModel:

using MvvmCross.Core.ViewModels;
using MvvmCross.Platform;
using MvvmCross.Plugins.PictureChooser;
using Plugin.Media;
using Plugin.Media.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;

namespace XamarinFormsCross2.Core.ViewModels
{
    public class SecondViewModel : BaseViewModel
    {
        string _message;
        public string Message { get { return _message; } set { SetProperty(ref _message, value); } }

        MvxCommand _photo2Command;
        public ICommand Photo2Command
        {
            get
            {
                return _photo2Command ?? (_photo2Command = new MvxCommand(async () =>
                {
                    var task = Mvx.Resolve<IMvxPictureChooserTask>();
                    var photo = await task.TakePictureAsync(500, 90);

                    if (photo == null)
                        return;

                    Photo = ImageSource.FromStream(() => photo);

                }));
            }
        }

        private ImageSource _photo;
        public ImageSource Photo { get { return _photo; } set { SetProperty(ref _photo, value); } }

        public SecondViewModel()
        {
            Message = "Segunda página!";
        }

        public void Init(string param)
        {
            if (param != null)
                Message = String.Format("{0} {1}", Message, param);
        }
    }
}

And this is the View:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XamarinFormsCross2.Core.Views.SecondPage"
             Title="Segunda página">
    <StackLayout>
        <Label Text="{Binding Message}" HorizontalOptions="Center" />
        <Button Text="Foto 2" Command="{Binding Photo2Command}"></Button>
        <Image Source="{Binding Photo}" BackgroundColor="Gray"></Image>        
    </StackLayout>  
</ContentPage>

I'm using Xamarin.Forms + MVVMCross

@Cheesebaron
Copy link
Member

Cheesebaron commented Nov 5, 2016

Must be something wrong with the conversion of the stream to bitmap in Forms.

If I use the native Image view and the MvxInMemoryImageValueConverter it works just fine.

capture

As you can see I captured a picture of my mug just fine.

private void DoPickPictureCommand()
{
    _pictureChooser.TakePicture(200, 100, (stream) =>
    {
        using (stream)
            ImageBytes = ReadFully(stream);
    }, () =>
    {

    });
}

private byte[] _imageBytes;

public byte[] ImageBytes
{
    get { return _imageBytes; }
    set
    {
        _imageBytes = value;
        RaisePropertyChanged(() => ImageBytes);
    }
}



public static byte[] ReadFully(Stream input)
{
    byte[] buffer = new byte[16 * 1024];
    using (MemoryStream ms = new MemoryStream())
    {
        int read;
        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            ms.Write(buffer, 0, read);
        }
        return ms.ToArray();
    }
}

And View:

<Image Source="{Binding ImageBytes, Converter={StaticResource InMemoryImage}}" />

@farlop
Copy link
Author

farlop commented Nov 5, 2016

As I'm using Xamarin.Forms for sharing the views (and TBH I'm all new in this Xamarin world), I will keep using Xam.Plugin.Media which seems to work just fine with similar implementation.

Anyway, the issue with the UWP assembly seems to be solved, so thank you for your help!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants