我想将位图图像存储在本地目录中。我写了那些代码。但是发生了未知错误,无法编译。请告诉我错误的原因以及转换和存储位图图像的正确方法。
void StoreAndGetBitmapImage()
{
BitmapImage image = new BitmapImage(new Uri("ms-appx:///Assets/" + "test.png"));
StorageFile storageFile = ConvertBitmapImageIntoStorageFile(image, "image_name");
StoreStorageFile(storageFile);
BitmapImage resultImage = GetBitmapImage("image_name");
}
StorageFile ConvertBitmapImageIntoStorageFile(BitmapImage bitmapImage,string fileName)
{
StorageFile file = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(bitmapImage.UriSource).GetResults();
file.RenameAsync(fileName);
return file;
}
void StoreStorageFile(StorageFile storageFile)
{
storageFile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);
}
BitmapImage GetBitmapImage(string fileName)
{
BitmapImage bitmapImage;
bitmapImage = new BitmapImage();
bitmapImage.UriSource = new Uri(new Uri(
Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\" +
Windows.Storage.ApplicationData.Current.LocalFolder.Name),
fileName);
return bitmapImage;
}