本文整理汇总了C#中Windows.Storage.StorageFolder.OpenStreamForWriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.OpenStreamForWriteAsync方法的具体用法?C# StorageFolder.OpenStreamForWriteAsync怎么用?C# StorageFolder.OpenStreamForWriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.OpenStreamForWriteAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public async Task Init(string appname) {
var devices = Windows.Storage.KnownFolders.RemovableDevices;
var sdCards = await devices.GetFoldersAsync();
if (sdCards.Count == 0) return;
_SDCard = sdCards[0];
string foldername = string.Format("{0}_Log", appname);
_LogFolder = await _SDCard.CreateFolderAsync(foldername, CreationCollisionOption.OpenIfExists);
_FileName = string.Format("{0:yyyy-MM-dd}.txt", DateTime.Now);
_Stream = await _LogFolder.OpenStreamForWriteAsync(_FileName, CreationCollisionOption.OpenIfExists);
}
示例2: GenerateIcon
async Task GenerateIcon(AppInfo appInfo, IconInfo iconInfo, StorageFolder folder)
{
// Draw the icon image into a command list.
var commandList = new CanvasCommandList(device);
using (var ds = commandList.CreateDrawingSession())
{
appInfo.DrawIconImage(ds, iconInfo);
}
ICanvasImage iconImage = commandList;
// Rasterize into a rendertarget.
var renderTarget = new CanvasRenderTarget(device, iconInfo.Width, iconInfo.Height, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
// Initialize with the appropriate background color.
ds.Clear(iconInfo.TransparentBackground ? Colors.Transparent : appInfo.BackgroundColor);
// Work out where to position the icon image.
var imageBounds = iconImage.GetBounds(ds);
imageBounds.Height *= 1 + iconInfo.BottomPadding;
float scaleUpTheSmallerIcons = Math.Max(1, 1 + (60f - iconInfo.Width) / 50f);
float imageScale = appInfo.ImageScale * scaleUpTheSmallerIcons;
var transform = Matrix3x2.CreateTranslation((float)-imageBounds.X, (float)-imageBounds.Y) *
Utils.GetDisplayTransform(renderTarget.Size.ToVector2(), new Vector2((float)imageBounds.Width, (float)imageBounds.Height)) *
Matrix3x2.CreateScale(imageScale, renderTarget.Size.ToVector2() / 2);
if (iconInfo.Monochrome)
{
// Optionally convert to monochrome.
iconImage = new DiscreteTransferEffect
{
Source = new Transform2DEffect
{
Source = new LuminanceToAlphaEffect { Source = iconImage },
TransformMatrix = transform
},
RedTable = new float[] { 1 },
GreenTable = new float[] { 1 },
BlueTable = new float[] { 1 },
AlphaTable = new float[] { 0, 1 }
};
}
else
{
ds.Transform = transform;
// Optional shadow effect.
if (appInfo.AddShadow)
{
var shadow = new ShadowEffect
{
Source = iconImage,
BlurAmount = 12,
};
ds.DrawImage(shadow);
}
}
// draw the main icon image.
ds.DrawImage(iconImage);
}
// Save to a file.
using (var stream = await folder.OpenStreamForWriteAsync(iconInfo.Filename, CreationCollisionOption.ReplaceExisting))
{
await renderTarget.SaveAsync(stream.AsRandomAccessStream(), CanvasBitmapFileFormat.Png);
}
}