gpt4 book ai didi

ios - 分享图像 Xamarin Ios

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:59:03 24 4
gpt4 key购买 nike

我正在使用 Xamarin 表单,并且在我的应用程序中有一个按钮可以分享我在使用 Intent 时遇到的问题,但在我的应用程序 ios 中不知道该怎么做,有人可以帮助我?

使用安卓

public async Task<bool> Share(ImageSource image)
{
Intent shareIntent = new Intent(Intent.ActionSend);

bitmapToShare = await GetBitmap (image);

if (bitmapToShare != null) {

CreateDirectoryForPictures("Xpto");

var filePath = System.IO.Path.Combine (dir.AbsolutePath, string.Format("xpto_{0}.png",Guid.NewGuid()));
var stream = new FileStream (filePath, FileMode.Create);
bitmapToShare.Compress (Bitmap.CompressFormat.Png, 100, stream);
stream.Close ();

Java.IO.File file = new Java.IO.File (filePath);

shareIntent.SetType ("image/*");
shareIntent.PutExtra (Intent.ExtraStream, Android.Net.Uri.FromFile (file));
shareIntent.AddFlags (ActivityFlags.GrantReadUriPermission);
Forms.Context.StartActivity (Intent.CreateChooser (shareIntent, "Compartilhar"));
}

return true;
}

最佳答案

    private static async Task ShareImageAsyc(ImageSource image, string message, string url = null)
{
var handler = image.GetHandler();

if (handler == null) return;

var uiImage = await handler.LoadImageAsync(image);

var items = new List<NSObject> { new NSString(message ?? string.Empty) };
if (!url.IsNullOrEmpty())
items.Add(new NSString(url));
items.Add(uiImage);

var controller = new UIActivityViewController(items.ToArray(), null);

UIApplication.SharedApplication.KeyWindow.RootViewController.GetTopViewController()
.PresentViewController(controller, true, null);
}

发件人:https://github.com/jimbobbennett/JimLib.Xamarin/blob/master/JimLib.Xamarin.ios/Sharing/Share.cs

关于ios - 分享图像 Xamarin Ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31323886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com