在c ++中使用secondaryTitle时,我必须输入一个指向徽标的URI。如果我尝试将其指向应用程序包外部的任何文件,则URI失败。我想要做的是让用户使用文件选择器选择文件
void App3::MainPage::FindLogo(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
FileOpenPicker^ openPicker = ref new FileOpenPicker();
openPicker->ViewMode = PickerViewMode::Thumbnail;
openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary;
openPicker->FileTypeFilter->Append(".jpg");
openPicker->FileTypeFilter->Append(".jpeg");
openPicker->FileTypeFilter->Append(".png");
create_task(openPicker->PickSingleFileAsync()).then([this](Windows::Storage::StorageFile^ file)
{
if (file)
{
StorageFolder^ folder;
auto ur = ref new Uri("ms-appx:///Assets//");
String^ s = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
create_task(StorageFolder::GetFolderFromPathAsync(s)).then([=](StorageFolder^ folder){
create_task(file->CopyAsync(folder, file->Name, NameCollisionOption::ReplaceExisting)).then([this, file](task<StorageFile^> task)
{
logoFile = ref new Uri("ms-appdata:///local//App3//Assets//StoreLogo.scale-100.png");
});
});
}
});
}
然后复制该文件并将其保存在应用程序目录中。使用uri指向新副本时,它仍然失败。
void App3::MainPage::kk(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
text = url->Text->ToString();
ids = id->Text->ToString();
auto test = ref new Windows::UI::StartScreen::SecondaryTile(ids, "hi", text, logoFile, Windows::UI::StartScreen::TileSize::Square150x150); // Breaks right here
//错误:徽标文件为0x05fcc1d0
num++;
test->RequestCreateAsync();
//auto uri = ref new Windows::Foundation::Uri("http://www.google.com");
//concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
}
更新
create_task(openPicker->PickSingleFileAsync()).then([this](Windows::Storage::StorageFile^ file)
{
if (file)
{
StorageFolder^ folder = ApplicationData::Current->LocalFolder;
create_task(file->CopyAsync(folder, file->Name, NameCollisionOption::ReplaceExisting)).then([this, file](task<StorageFile^> task)
{
String^ path = "ms-appdata:///local/" + file->Name;
logoFile = ref new Uri(path);
});
}
});
您正在尝试将选择的文件复制到应用程序包位置(InstalledLocation),而不是复制到应用程序数据文件夹中。程序包位置是只读的,因此CopyAsync应该失败。使用StorageFolder ^ localFolder = ApplicationData :: Current-> LocalFolder; 反而。
另外,您确实需要ms / appdata:/// local中的///,因为它是省略包ID的简写,但是您只需要在URI中的其他位置输入一个/。
最后,请注意,平铺图片必须小于等于200KB,小于等于1024x1024,否则根本不会显示。如果您使用的是照片图像,请使用JPEG压缩;否则,请使用JPEG压缩。矢量图像最好使用PNG压缩。有关处理此问题的更多信息,请参阅我的免费电子书的第16章,使用HTML,CSS和JavaScript编程Windows Store应用程序,第二版,特别是从第887页开始的“基本磁贴更新”和在第899页的侧栏。内容为适用于以所有语言编写的应用,并且是一本免费的书,因此没有风险。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句