gpt4 book ai didi

windows-8 - 如何在 Windows 8 Metro 应用程序 C# 中将保存缩略图图像存储在设备中

转载 作者:行者123 更新时间:2023-12-04 23:23:11 24 4
gpt4 key购买 nike

我正在使用此代码创建缩略图并在框架中显示

平台 -> 使用 c# 的 windows 8 Metro 应用程序

http://code.msdn.microsoft.com/windowsapps/File-and-folder-thumbnail-1d530e5d

在使用 c# 的 Windows 8 Metro 应用程序中。我需要保存或存储(在设备中)我在运行时创建的缩略图。在constants.cs 类文件的DisplayResult() 中,我需要将该图像保存在设备中如何实现这一点。请给我一些想法或示例,我对移动设备很陌生,从未处理过图像和缩略图部分。提前致谢 。

最佳答案

尝试这个。以下代码将选择的音频文件的专辑封面保存在 TempFolder 中

private async void btnPickFile_Click(object sender, RoutedEventArgs e)
{
string[] Music = new string[] { ".mp3", ".wma", ".m4a", ".aac" };
FileOpenPicker openPicker = new FileOpenPicker();
foreach (string extension in Music)
{
openPicker.FileTypeFilter.Add(extension);
}

StorageFile file = await openPicker.PickSingleFileAsync();
if (file != null)
{
await SaveThumbnail("MySongThumb.png", file);
}
}

private async Task SaveThumbnail(string ThumbnailName, StorageFile file)
{
if (file != null)
{
using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.MusicView, 100))
{
if (thumbnail != null && thumbnail.Type == ThumbnailType.Image)
{
var destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(ThumbnailName, CreationCollisionOption.GenerateUniqueName);
Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(thumbnail.Size));
IBuffer iBuf = await thumbnail.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
using (var strm = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
{
await strm.WriteAsync(iBuf);
}
}
}
}
}

更新 1

private async Task<StorageFile> SaveThumbnail(StorageItemThumbnail objThumbnail)
{
if (objThumbnail != null && objThumbnail.Type == ThumbnailType.Image)
{
var picker = new FileSavePicker();
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeChoices.Add("JPEG Image", new string[] { ".jpg" });
picker.FileTypeChoices.Add("PNG Image", new string[] { ".png" });
StorageFile destinationFile = await picker.PickSaveFileAsync();

if (destinationFile != null)
{
Windows.Storage.Streams.Buffer MyBuffer = new Windows.Storage.Streams.Buffer(Convert.ToUInt32(objThumbnail.Size));
IBuffer iBuf = await objThumbnail.ReadAsync(MyBuffer, MyBuffer.Capacity, InputStreamOptions.None);
using (var strm = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
{
await strm.WriteAsync(iBuf);
}
}

return destinationFile;
}
else
{
return null;
}
}

关于windows-8 - 如何在 Windows 8 Metro 应用程序 C# 中将保存缩略图图像存储在设备中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18843315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com