本文整理汇总了C#中System.IO.MemoryStream.AsOutputStream方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.AsOutputStream方法的具体用法?C# MemoryStream.AsOutputStream怎么用?C# MemoryStream.AsOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.AsOutputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PageBlobDownloadToStreamRangeTestAsync
public async Task PageBlobDownloadToStreamRangeTestAsync()
{
byte[] buffer = GetRandomBuffer(2 * 1024);
CloudPageBlob blob = this.testContainer.GetPageBlobReference("blob1");
using (MemoryStream wholeBlob = new MemoryStream(buffer))
{
await blob.UploadFromStreamAsync(wholeBlob.AsInputStream());
byte[] testBuffer = new byte[1024];
MemoryStream blobStream = new MemoryStream(testBuffer);
Exception ex = await TestHelper.ExpectedExceptionAsync<Exception>(
async () => await blob.DownloadRangeToStreamAsync(blobStream.AsOutputStream(), 0, 0),
"Requesting 0 bytes when downloading range should not work");
Assert.IsInstanceOfType(ex.InnerException.InnerException, typeof(ArgumentOutOfRangeException));
await blob.DownloadRangeToStreamAsync(blobStream.AsOutputStream(), 0, 1024);
Assert.AreEqual(blobStream.Position, 1024);
TestHelper.AssertStreamsAreEqualAtIndex(blobStream, wholeBlob, 0, 0, 1024);
CloudPageBlob blob2 = this.testContainer.GetPageBlobReference("blob1");
MemoryStream blobStream2 = new MemoryStream(testBuffer);
ex = await TestHelper.ExpectedExceptionAsync<Exception>(
async () => await blob2.DownloadRangeToStreamAsync(blobStream.AsOutputStream(), 1024, 0),
"Requesting 0 bytes when downloading range should not work");
Assert.IsInstanceOfType(ex.InnerException.InnerException, typeof(ArgumentOutOfRangeException));
await blob2.DownloadRangeToStreamAsync(blobStream2.AsOutputStream(), 1024, 1024);
TestHelper.AssertStreamsAreEqualAtIndex(blobStream2, wholeBlob, 0, 1024, 1024);
AssertAreEqual(blob, blob2);
}
}
示例2: InitializeAsync
public async Task InitializeAsync()
{
if (_isInitialized)
{
return;
}
IReadOnlyList<Size> availableCaptureResulotions =
PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
Device = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, availableCaptureResulotions.First());
InitParameters();
Device.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true);
_captureStream = new MemoryStream();
_captureSequence = Device.CreateCaptureSequence(1);
_captureSequence.Frames[0].CaptureStream = _captureStream.AsOutputStream();
await Device.PrepareCaptureSequenceAsync(_captureSequence);
CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed;
CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed;
CameraButtons.ShutterKeyReleased += CameraButtons_ShutterKeyReleased;
_isInitialized = true;
}
示例3: FileOpenWriteTestAsync
public async Task FileOpenWriteTestAsync()
{
byte[] buffer = GetRandomBuffer(2 * 1024);
CloudFileShare share = GetRandomShareReference();
try
{
await share.CreateAsync();
CloudFile file = share.GetRootDirectoryReference().GetFileReference("file1");
using (ICloudFileStream fileStream = await file.OpenWriteAsync(2048))
{
Stream fileStreamForWrite = fileStream.AsStreamForWrite();
await fileStreamForWrite.WriteAsync(buffer, 0, 2048);
await fileStreamForWrite.FlushAsync();
byte[] testBuffer = new byte[2048];
MemoryStream dstStream = new MemoryStream(testBuffer);
await file.DownloadRangeToStreamAsync(dstStream.AsOutputStream(), null, null);
MemoryStream memStream = new MemoryStream(buffer);
TestHelper.AssertStreamsAreEqual(memStream, dstStream);
}
}
finally
{
share.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例4: DownloadTextAsync
public static async Task<string> DownloadTextAsync(CloudFile file, Encoding encoding, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null)
{
using (MemoryStream stream = new MemoryStream())
{
await file.DownloadToStreamAsync(stream.AsOutputStream(), accessCondition, options, operationContext);
return encoding.GetString(stream.ToArray(), 0, (int)stream.Length);
}
}
示例5: FileDownloadToStreamRangeTestAsync
public async Task FileDownloadToStreamRangeTestAsync()
{
byte[] buffer = GetRandomBuffer(2 * 1024);
CloudFileShare share = GetRandomShareReference();
try
{
await share.CreateAsync();
CloudFile file = share.GetRootDirectoryReference().GetFileReference("file1");
using (MemoryStream wholeFile = new MemoryStream(buffer))
{
await file.UploadFromStreamAsync(wholeFile.AsInputStream());
byte[] testBuffer = new byte[1024];
MemoryStream fileStream = new MemoryStream(testBuffer);
Exception ex = await TestHelper.ExpectedExceptionAsync<Exception>(
async () => await file.DownloadRangeToStreamAsync(fileStream.AsOutputStream(), 0, 0),
"Requesting 0 bytes when downloading range should not work");
Assert.IsInstanceOfType(ex.InnerException.InnerException, typeof(ArgumentOutOfRangeException));
await file.DownloadRangeToStreamAsync(fileStream.AsOutputStream(), 0, 1024);
Assert.AreEqual(fileStream.Position, 1024);
TestHelper.AssertStreamsAreEqualAtIndex(fileStream, wholeFile, 0, 0, 1024);
CloudFile file2 = share.GetRootDirectoryReference().GetFileReference("file1");
MemoryStream fileStream2 = new MemoryStream(testBuffer);
ex = await TestHelper.ExpectedExceptionAsync<Exception>(
async () => await file2.DownloadRangeToStreamAsync(fileStream.AsOutputStream(), 1024, 0),
"Requesting 0 bytes when downloading range should not work");
Assert.IsInstanceOfType(ex.InnerException.InnerException, typeof(ArgumentOutOfRangeException));
await file2.DownloadRangeToStreamAsync(fileStream2.AsOutputStream(), 1024, 1024);
TestHelper.AssertStreamsAreEqualAtIndex(fileStream2, wholeFile, 0, 1024, 1024);
AssertAreEqual(file, file2);
}
}
finally
{
share.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例6: Button_Click_2
private async void Button_Click_2(object sender, RoutedEventArgs e) {
CameraCaptureSequence cameraCaptureSequence = _cam.CreateCaptureSequence(1);
MemoryStream stream = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = stream.AsOutputStream();
await _cam.PrepareCaptureSequenceAsync(cameraCaptureSequence);
await cameraCaptureSequence.StartCaptureAsync();
stream.Seek(0, SeekOrigin.Begin);
var library = new MediaLibrary();
library.SavePictureToCameraRoll("pic1.jpg", stream);
}
示例7: RestoreAsync
public async Task RestoreAsync()
{
var file = await ApplicationData.Current.LocalFolder.GetFileAsync(SessionStateFileName);
using (var inStream = await file.OpenSequentialReadAsync())
{
using (var memoryStream = new MemoryStream())
{
var provider = new DataProtectionProvider("LOCAL=user");
await provider.UnprotectStreamAsync(inStream, memoryStream.AsOutputStream());
memoryStream.Seek(0, SeekOrigin.Begin);
var bytes = memoryStream.ToArray();
this.DeserializeState(bytes);
}
}
this.LoadApplicationState();
}
示例8: Button_Click_1
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
CameraCaptureSequence seq;
seq = captureDevice.CreateCaptureSequence(1);
seq.Frames[0].DesiredProperties[KnownCameraPhotoProperties.SceneMode] = CameraSceneMode.Portrait;
MemoryStream captureStream1 = new MemoryStream();
seq.Frames[0].CaptureStream = captureStream1.AsOutputStream();
await captureDevice.PrepareCaptureSequenceAsync(seq);
await seq.StartCaptureAsync();
captureStream1.Seek(0, SeekOrigin.Begin);
MediaLibrary mediaLibrary = new MediaLibrary();
mediaLibrary.SavePictureToCameraRoll( "1111.jpg", captureStream1);
}
示例9: MainPage_Loaded
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
using (MemoryStream stream = new MemoryStream())
using (var camera = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First()))
{
var sequence = camera.CreateCaptureSequence(1);
sequence.Frames[0].CaptureStream = stream.AsOutputStream();
camera.PrepareCaptureSequenceAsync(sequence);
await sequence.StartCaptureAsync();
stream.Seek(0, SeekOrigin.Begin);
using (var library = new MediaLibrary())
{
library.SavePictureToCameraRoll("currentImage.jpg", stream);
BitmapImage licoriceImage = new BitmapImage(new Uri("currentImage.jpg", UriKind.Relative));
imgPlace.Source = licoriceImage;
}
}
}
示例10: CloudBlockBlobDownloadToStreamCancelAsync
public async Task CloudBlockBlobDownloadToStreamCancelAsync()
{
byte[] buffer = GetRandomBuffer(1 * 1024 * 1024);
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
CloudBlockBlob blob = container.GetBlockBlobReference("blob1");
using (MemoryStream originalBlob = new MemoryStream(buffer))
{
await blob.UploadFromStreamAsync(originalBlob.AsInputStream());
using (MemoryStream downloadedBlob = new MemoryStream())
{
OperationContext operationContext = new OperationContext();
IAsyncAction action = blob.DownloadToStreamAsync(downloadedBlob.AsOutputStream(), null, null, operationContext);
await Task.Delay(100);
action.Cancel();
try
{
await action;
}
catch (Exception)
{
Assert.AreEqual(operationContext.LastResult.Exception.Message, "A task was canceled.");
Assert.AreEqual(operationContext.LastResult.HttpStatusCode, 306);
//Assert.AreEqual(operationContext.LastResult.HttpStatusMessage, "Unused");
}
TestHelper.AssertNAttempts(operationContext, 1);
}
}
}
finally
{
container.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例11: CloudPageBlobUploadFromStreamAsync
private async Task CloudPageBlobUploadFromStreamAsync(CloudBlobContainer container, int size, AccessCondition accessCondition, OperationContext operationContext, int startOffset)
{
byte[] buffer = GetRandomBuffer(size);
CryptographicHash hasher = HashAlgorithmProvider.OpenAlgorithm("MD5").CreateHash();
hasher.Append(buffer.AsBuffer(startOffset, buffer.Length - startOffset));
string md5 = CryptographicBuffer.EncodeToBase64String(hasher.GetValueAndReset());
CloudPageBlob blob = container.GetPageBlobReference("blob1");
blob.StreamWriteSizeInBytes = 512;
using (MemoryStream originalBlob = new MemoryStream())
{
originalBlob.Write(buffer, startOffset, buffer.Length - startOffset);
using (MemoryStream sourceStream = new MemoryStream(buffer))
{
sourceStream.Seek(startOffset, SeekOrigin.Begin);
BlobRequestOptions options = new BlobRequestOptions()
{
StoreBlobContentMD5 = true,
};
await blob.UploadFromStreamAsync(sourceStream.AsInputStream(), accessCondition, options, operationContext);
}
await blob.FetchAttributesAsync();
Assert.AreEqual(md5, blob.Properties.ContentMD5);
using (MemoryStream downloadedBlob = new MemoryStream())
{
await blob.DownloadToStreamAsync(downloadedBlob.AsOutputStream());
TestHelper.AssertStreamsAreEqual(originalBlob, downloadedBlob);
}
}
}
示例12: BlobOpenWriteTestAsync
public async Task BlobOpenWriteTestAsync()
{
byte[] buffer = GetRandomBuffer(2 * 1024);
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
CloudPageBlob blob = container.GetPageBlobReference("blob1");
using (ICloudBlobStream blobStream = await blob.OpenWriteAsync(2048))
{
Stream blobStreamForWrite = blobStream.AsStreamForWrite();
await blobStreamForWrite.WriteAsync(buffer, 0, 2048);
await blobStreamForWrite.FlushAsync();
byte[] testBuffer = new byte[2048];
MemoryStream dstStream = new MemoryStream(testBuffer);
await blob.DownloadRangeToStreamAsync(dstStream.AsOutputStream(), null, null);
MemoryStream memStream = new MemoryStream(buffer);
TestHelper.AssertStreamsAreEqual(memStream, dstStream);
}
}
finally
{
container.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例13: CloudBlockBlobUploadDownloadNoDataAsync
public async Task CloudBlockBlobUploadDownloadNoDataAsync()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
CloudBlockBlob blob = container.GetBlockBlobReference("blob");
await TestHelper.ExpectedExceptionAsync<ArgumentNullException>(
async () => await blob.UploadFromStreamAsync(null),
"Uploading from a null stream should fail");
using (MemoryStream stream = new MemoryStream())
{
await blob.UploadFromStreamAsync(stream.AsInputStream());
}
await TestHelper.ExpectedExceptionAsync<ArgumentNullException>(
async () => await blob.DownloadToStreamAsync(null),
"Downloading to a null stream should fail");
using (MemoryStream stream = new MemoryStream())
{
await blob.DownloadToStreamAsync(stream.AsOutputStream());
Assert.AreEqual(0, stream.Length);
}
}
finally
{
container.DeleteIfExistsAsync().AsTask().Wait();
}
}
示例14: StartCapturingAsync
private async Task StartCapturingAsync()
{
CameraCaptureSequence sequence = PhotoCaptureDevice.CreateCaptureSequence(1);
var memoryStream = new MemoryStream();
sequence.Frames[0].CaptureStream = memoryStream.AsOutputStream();
try
{
PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off);
PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.SceneMode, CameraSceneMode.Macro);
}
catch
{
// one or more properties not supported
}
await PhotoCaptureDevice.PrepareCaptureSequenceAsync(sequence);
}
示例15: TakePicture
public async Task<IBuffer> TakePicture()
{
if (m_captureDevice == null || commandeRunning)
return null;
try
{
commandeRunning = true;
int angle = (int)(m_orientationAngle + m_captureDevice.SensorRotationInDegrees);
if (angle < 0) angle += 360;
if (m_sensorLocation == CameraSensorLocation.Back)
{
m_captureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, angle);
}
else
{
m_captureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, -angle);
}
m_captureDevice.SetProperty(KnownCameraGeneralProperties.SpecifiedCaptureOrientation, 0);
var cameraCaptureSequence = m_captureDevice.CreateCaptureSequence(1);
var stream = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = stream.AsOutputStream();
await m_captureDevice.PrepareCaptureSequenceAsync(cameraCaptureSequence);
await cameraCaptureSequence.StartCaptureAsync();
if (m_sensorLocation == CameraSensorLocation.Back)
{
return stream.GetWindowsRuntimeBuffer();
}
else
{
return await JpegTools.FlipAndRotateAsync(stream.GetWindowsRuntimeBuffer(), FlipMode.Horizontal, Rotation.Rotate0, JpegOperation.AllowLossy);
}
}
finally
{
commandeRunning = false;
}
return null;
}