Reputation: 75
I am trying to pass a camera overlay function as a dependency service into my shared code using the Media Plugin for Xamarin https://github.com/jamesmontemagno/MediaPlugin.
I can not figure out how to implement the dependency service correctly. The app runs but when I open the camera, it doesn't display the overlay. If someone could help me with my code, or direct me to an example of using the overlay option, I would really appreciate it.
My interface code:
public interface IPhotoOverlay
{
object GetImageOverlayAsync();
}
My iOS code:
public object GetImageOverlayAsync()
{
Func<object> func = CreateOverlay;
return func;
}
public object CreateOverlay()
{
var imageView = new UIImageView(UIImage.FromBundle("face-template.png"));
imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
var screen = UIScreen.MainScreen.Bounds;
imageView.Frame = screen;
return imageView;
}
My shared code:
var photo = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions() {
OverlayViewProvider = DependencyService.Get<IPhotoOverlay>().GetImageOverlayAsync,
DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front});
Upvotes: 0
Views: 802
Reputation: 7189
In your Xamarin.iOS Service, you need to register the Dependency, here is an example.
[assembly: Dependency (typeof (PhotoOverlayiOS))]
namespace UsingDependencyService.iOS
{
public class PhotoOverlayiOS : IPhotoOverlay
{
public object GetImageOverlayAsync()
{
Func<object> func = CreateOverlay;
return func;
}
public object CreateOverlay()
{
var imageView = new UIImageView(UIImage.FromBundle("face-template.png"));
imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
var screen = UIScreen.MainScreen.Bounds;
imageView.Frame = screen;
return imageView;
}
}
}
Upvotes: 1