本文整理匯總了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);
}
}