【问题标题】:How can i open an image in it's full size in UWP如何在 UWP 中以全尺寸打开图像
【发布时间】:2017-02-13 23:03:15
【问题描述】:

我正在开发一个聊天应用程序:

如果用户点击图像,它将以全尺寸显示。调用如下方法:

Handle_Tapped()

void Handle_Tapped(object sender, System.EventArgs e)
    {
        try
        {
            Image image = sender as Image;
            string filePath = String.Empty;

            filePath = image.Source as FileImageSource;
            Eva3Toolkit.CommonUtils.openImage(filePath);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

哪些调用(取决于操作系统):

Android 中的openImage()

public void openImage(string filePath)
    {
        Intent sendIntent = new Intent(Intent.ActionView);
        sendIntent.SetDataAndType(Android.Net.Uri.Parse("file:" + filePath), "image/*");
        Forms.Context.StartActivity(Intent.CreateChooser(sendIntent, "Bild öffnen..."));
    }

openImage() 在 iOS 中

public void openImage(string filePath)
    {
        var firstController = ((UIApplicationDelegate)(UIApplication.SharedApplication.Delegate)).Window.RootViewController.ChildViewControllers[0].ChildViewControllers[1].ChildViewControllers[0];
        var navcontroller = firstController as UINavigationController;
        var docIC = UIDocumentInteractionController.FromUrl(new NSUrl(filePath, true));
        docIC.Delegate = new DocInteractionC(navcontroller);
        docIC.PresentPreview(true);
    }

现在想在UWP中创建一个方法openImage(),但是不知道。我知道我很可能不得不将图像作为 StorageFile 而不是路径,因为只有 StorageFile 授予我打开图像的权限。

有没有办法在 UWP 中以全尺寸打开图像?我非常不想为此创建新视图。

【问题讨论】:

    标签: image xaml xamarin uwp


    【解决方案1】:

    Launcher 可以使用分配给该文件的程序打开文件:

    public async void openImageAsync(string filePath)
        {
            StorageFile storageFile = await StorageFile.GetFileFromPathAsync(filePath);
            await Launcher.LaunchFileAsync(storageFile);
        }
    

    对于我的情况,我使用 filePath 是有效的,因为文件位于本地文件夹中。

    输出如下所示:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多