0
Je suis un débutant dans Xamarin.Forms, et j'ai une question: Comment puis-je appeler le code suivant dans mon code partagé/xaml.cs?Comment appeler le code de capture d'écran de dépendance dans mon code partagé?
public class screenshotManager : IScreenshotManager
{
public static Activity Activity { get; set; }
public async System.Threading.Tasks.Task<byte[]> CaptureAsync()
{
if (Activity == null)
{
throw new Exception("You have to set ScreenshotManager.Activity in your Android project");
}
var view = Activity.Window.DecorView;
view.DrawingCacheEnabled = true;
Bitmap bitmap = view.GetDrawingCache(true);
byte[] bitmapData;
using (var stream = new MemoryStream())
{
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
bitmapData = stream.ToArray();
}
return bitmapData;
}
}
Avez-vous lu les documents? https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/ – Jason
ive a tenté de placer ce code dans un événement click mais rien ne s'est produit DependencyService.Get(). CaptureAsync(); –
Avez-vous enregistré votre implémentation? '[assembly: Xamarin.Forms.Dependency (typeof (screenshotManager))]' en tant que [demande à docs] (https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/ #Enregistrement)? –