zoukankan      html  css  js  c++  java
  • 读取 windows8 WinRT组件项目中的一个文件

     
    假设WinRT组件项目的目录结构如下图,现在需要读取pista_454_big.jpg文件:
     

     
    我在Class1中写一个名为GetFile的方法,其中的代码如下:
     
    StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
    StorageFolder subfolder1 = await installedLocation.GetFolderAsync("WindowsRuntimeComponent1");
    StorageFolder subfolder2 = await subfolder1.GetFolderAsync("Pictures");
    StorageFile sampleFile = await installedLocation.GetFileAsync("pista_454_big.jpg");
     
    由于WinRT组件是无法单独运行的,它一定要被另一个Windows Store应用程序调用的。我们可以拿到这个应用程序的安装路径(Windows.ApplicationModel.Package.Current.InstalledLocation)。然后WinRT组件在这个应用程序的安装路径下会有一个以WinRT组件名字命名的文件夹("WindowsRuntimeComponent1",在这个文件夹下面就能找到WinRT组件项目中的子文件夹了"Pictures")。
     
    当然您还可以使用GetFoldersAsync来列出安装目录下的所有子文件夹。

     
    URI的方式不行。在Windows Store应用程序里面我们可以用如下代码访问到WinRT组件中的图片(我们假设Windows Store应用程序的solution里面包含了名为WindowsRuntimeComponent1WinRT组件工程):
     
    Uri pic = newUri(this.BaseUri, "/WindowsRuntimeComponent1/Picture/pista_454_big.jpg");
     
    但是上面这行代码放到WinRT组件里面是不行的。即使类继承了FrameworkElement类,BaseUri的值也是null
     
    而如果上面这行代码写在Windows Store应用程序里面,BaseUri的值就是应用程序的根目录,然后就能访问到WinRT组件里面的图片了。

  • 相关阅读:
    cmd命令操作Mysql数据库
    可编程作息时间控制器设计
    博客第一天
    PRML 1: Gaussian Distribution
    KMP String Matching Algorithm
    Reinstall Ubuntu 14.04
    Computability 4: Decidability and R.E. Sets (I)
    Consumer-Producer Problem
    Compile the Linux Kernel
    Introduction to Linux Kernel
  • 原文地址:https://www.cnblogs.com/piaocz/p/2672024.html
Copyright © 2011-2022 走看看