首页 文章

如何在UWP中以完整尺寸打开图像

提问于
浏览
0

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

Chat

如果用户点击图像,它将以完整大小显示 . 调用以下方法:

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;
        }
    }

哪些电话(取决于操作系统):

openImage() in Android

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() in 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中打开全尺寸的图像?我更倾向于不为此创建新视图 .

1 回答

  • 0

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

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

    对于我的情况,它使用 filePath 工作,因为文件在本地文件夹中 .

    输出如下所示:

    enter image description here

相关问题