本文整理汇总了C#中System.IO.MemoryStream.GetWindowsRuntimeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.GetWindowsRuntimeBuffer方法的具体用法?C# MemoryStream.GetWindowsRuntimeBuffer怎么用?C# MemoryStream.GetWindowsRuntimeBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.GetWindowsRuntimeBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StreamToBuffer
/// <summary>
/// Returns a buffer with the contents of the given stream.
/// <param name="stream">Source stream</param>
/// <returns>Buffer with the contents of the given stream</returns>
/// </summary>
private IBuffer StreamToBuffer(Stream stream)
{
var memoryStream = stream as MemoryStream;
if (memoryStream == null)
{
using (memoryStream = new MemoryStream())
{
stream.Position = 0;
stream.CopyTo(memoryStream);
try
{
// Some stream types do not support flushing
stream.Flush();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return memoryStream.GetWindowsRuntimeBuffer();
}
}
else
{
return memoryStream.GetWindowsRuntimeBuffer();
}
}
示例2: SampleOriginalImage
// Sample the original image
private void SampleOriginalImage()
{
originalBitmap = new WriteableBitmap(originalImage);
double ratio = (double)originalBitmap.PixelWidth / (double)originalBitmap.PixelHeight;
double w = Application.Current.RootVisual.RenderSize.Width;
double h = Application.Current.RootVisual.RenderSize.Height;
double previewWidth;
double previewHeight;
if (w / ratio > h)
{
previewHeight = h;
previewWidth = h * ratio;
}
else
{
previewWidth = w;
previewHeight = w / ratio;
}
originalPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
currentPreviewBitmap = originalBitmap.Resize((int)previewWidth, (int)previewHeight, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
// Create buffer
previewStream = new MemoryStream();
currentPreviewBitmap.SaveJpeg(previewStream, originalPreviewBitmap.PixelWidth, originalPreviewBitmap.PixelHeight, 0, 75);
previewBuffer = previewStream.GetWindowsRuntimeBuffer();
}
示例3: GetServerChallenge
private IBuffer GetServerChallenge()
{
using (var ms = new MemoryStream())
{
using (var sw = new StreamWriter(ms))
{
sw.Write(_serverChallenge);
}
return ms.GetWindowsRuntimeBuffer();
}
}
示例4: SaveAsync
/// <summary>Saves the current session state. </summary>
public static async Task SaveAsync()
{
foreach (var weakFrameReference in _registeredFrames)
{
MtFrame frame;
if (weakFrameReference.TryGetTarget(out frame))
SaveFrameNavigationState(frame);
}
var sessionData = new MemoryStream();
var serializer = new DataContractSerializer(typeof(Dictionary<string, object>), _knownTypes);
serializer.WriteObject(sessionData, _sessionState);
var folder = ApplicationData.Current.LocalFolder;
var file = await folder.CreateFileAsync(SessionStateFilename, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBufferAsync(file, sessionData.GetWindowsRuntimeBuffer());
}
示例5: ApplyFilterToBackgroundImageAsync
private async void ApplyFilterToBackgroundImageAsync()
{
MemoryStream bitmapStream = new MemoryStream();
Source.SaveJpeg(bitmapStream, Source.PixelWidth, Source.PixelHeight, 0, 50);
IBuffer bmpBuffer = bitmapStream.GetWindowsRuntimeBuffer();
// Output buffer
WriteableBitmap outputImage = new WriteableBitmap(Source.PixelWidth, Source.PixelHeight);
using (EditingSession editsession = new EditingSession(bmpBuffer))
{
// First add an antique effect
editsession.AddFilter(FilterFactory.CreateBlurFilter(BlurLevel.Blur6));
// Finally, execute the filtering and render to a bitmap
await editsession.RenderToBitmapAsync(outputImage.AsBitmap());
outputImage.Invalidate();
FadeInNewImage(outputImage);
}
}
示例6: RestorePhotoModel
public static PhotoModel RestorePhotoModel()
{
PhotoModel model = null;
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
// parameters.xml
if (storage.FileExists(_photoModelPath + @"\" + _photoModelPropertiesFilename))
{
IsolatedStorageFileStream propertiesFile = storage.OpenFile(_photoModelPath + @"\" + _photoModelPropertiesFilename, FileMode.Open, FileAccess.Read);
XmlSerializer serializer = new XmlSerializer(typeof(PhotoModel));
model = serializer.Deserialize(propertiesFile) as PhotoModel;
propertiesFile.Flush();
propertiesFile.Close();
}
// buffer.data
if (model != null && storage.FileExists(_photoModelPath + @"\" + _photoModelBufferFilename))
{
IsolatedStorageFileStream originalFile = storage.OpenFile(_photoModelPath + @"\" + _photoModelBufferFilename, FileMode.Open, FileAccess.Read);
MemoryStream stream = new MemoryStream();
originalFile.CopyTo(stream);
model.Buffer = stream.GetWindowsRuntimeBuffer();
originalFile.Flush();
originalFile.Close();
}
}
return model;
}
示例7: Process
/// <summary>
/// Begins a photo stream item rendering process loop. Loop is executed asynchronously item by item
/// until there are no more items in the queue.
/// </summary>
private async void Process()
{
_processingNow++;
while (_enabled && Count > 0)
{
StreamItemViewModel item;
if (_priorityQueue.Count > 0)
{
Busy = true;
item = _priorityQueue[0];
_priorityQueue.RemoveAt(0);
}
else
{
item = _standardQueue[0];
_standardQueue.RemoveAt(0);
}
try
{
WriteableBitmap bitmap = null;
using (MemoryStream thumbnailStream = new MemoryStream())
{
System.Diagnostics.Debug.Assert(item.RequestedSize != StreamItemViewModel.Size.None);
if (item.RequestedSize == StreamItemViewModel.Size.Large)
{
bitmap = new WriteableBitmap(280, 280);
item.Model.Picture.GetImage().CopyTo(thumbnailStream);
}
else if (item.RequestedSize == StreamItemViewModel.Size.Medium)
{
bitmap = new WriteableBitmap(140, 140);
item.Model.Picture.GetThumbnail().CopyTo(thumbnailStream);
}
else
{
bitmap = new WriteableBitmap(70, 70);
item.Model.Picture.GetThumbnail().CopyTo(thumbnailStream);
}
using (EditingSession session = new EditingSession(thumbnailStream.GetWindowsRuntimeBuffer()))
{
Windows.Foundation.Rect rect;
if (session.Dimensions.Width > session.Dimensions.Height)
{
rect = new Windows.Foundation.Rect()
{
Width = session.Dimensions.Height,
Height = session.Dimensions.Height,
X = session.Dimensions.Width / 2 - session.Dimensions.Height / 2,
Y = 0
};
}
else
{
rect = new Windows.Foundation.Rect()
{
Width = session.Dimensions.Width,
Height = session.Dimensions.Width,
X = 0,
Y = session.Dimensions.Height / 2 - session.Dimensions.Width / 2
};
}
session.AddFilter(FilterFactory.CreateCropFilter(rect));
if (item.Model.Filter != null)
{
foreach (IFilter f in item.Model.Filter.Components)
{
session.AddFilter(f);
}
}
await session.RenderToBitmapAsync(bitmap.AsBitmap());
}
}
item.TransitionToImage(bitmap);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Rendering stream item failed:" + ex.Message);
item.TransitionToImage(null);
//.........这里部分代码省略.........
示例8: Task_Completed
private async void Task_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
if (Helpers.FileHelpers.IsValidPicture(e.OriginalFileName))
{
if (App.PhotoModel != null)
{
App.PhotoModel.Dispose();
App.PhotoModel = null;
GC.Collect();
}
using (MemoryStream stream = new MemoryStream())
{
e.ChosenPhoto.CopyTo(stream);
App.PhotoModel = new PhotoModel() { Buffer = stream.GetWindowsRuntimeBuffer() };
App.PhotoModel.Captured = (sender == _cameraCaptureTask);
App.PhotoModel.Dirty = App.PhotoModel.Captured;
App.PhotoModel.Path = e.OriginalFileName;
}
if (_loaded)
{
await SetupAsync();
await RenderAsync();
}
}
else
{
MessageBox.Show(AppResources.App_MessageBox_UnsupportedImage_Message,
AppResources.App_MessageBox_UnsupportedImage_Caption, MessageBoxButton.OK);
}
}
}
示例9: 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;
}
示例10: Capture
private async System.Threading.Tasks.Task Capture()
{
try
{
await camera.FocusAsync();
MemoryStream imageStream = new MemoryStream();
imageStream.Seek(0, SeekOrigin.Begin);
CameraCaptureSequence sequence = camera.CreateCaptureSequence(1);
sequence.Frames[0].CaptureStream = imageStream.AsOutputStream();
await camera.PrepareCaptureSequenceAsync(sequence);
await sequence.StartCaptureAsync();
camera.SetProperty(
KnownCameraPhotoProperties.LockedAutoFocusParameters,
AutoFocusParameters.None);
MediaLibrary library = new MediaLibrary();
EditingSession session = new EditingSession(imageStream.GetWindowsRuntimeBuffer());
using (session)
{
session.AddFilter(FilterFactory.CreateSketchFilter(SketchMode.Gray));
IBuffer data = await session.RenderToJpegAsync();
library.SavePictureToCameraRoll(FileNamePrefix
+ DateTime.Now.ToString() + ".jpg",
data.AsStream());
}
}
catch (Exception ex)
{
Debug.WriteLine("Failed to save the image to camera roll: " + ex.ToString());
}
}
示例11: ApplyEffect
public async Task<Stream> ApplyEffect(MemoryStream inputStream)
{
if (_effectIndex >= 0 && _effectIndex < EffectGroup.Count)
{
AbstractFilter filter = EffectGroup[_effectIndex];
IBuffer outputBuffer = null;
if (_semaphore.WaitOne(500))
{
outputBuffer = await filter.RenderJpegAsync(inputStream.GetWindowsRuntimeBuffer());
_semaphore.Release();
}
if (outputBuffer != null)
{
return outputBuffer.AsStream();
}
}
return null;
}
示例12: GenerateResponseHash
private void GenerateResponseHash()
{
var ae = new UTF8Encoding();
var v = NextInt64();
// Create cnonce value using a random number, username and password
var sb = new StringBuilder();
sb.Append(v.ToString());
sb.Append(":");
sb.Append(Id.User);
sb.Append(":");
sb.Append(Password);
_cnonce = HexString(ae.GetBytes(sb.ToString())).ToLower();
// Create the nonce count which states how many times we have sent this packet.
_nc++;
_ncString = _nc.ToString().PadLeft(8, '0');
// Create H1. This value is the username/password portion of A1 according to the SASL DIGEST-MD5 RFC.
sb.Remove(0, sb.Length);
sb.Append(Id.User);
sb.Append(":");
sb.Append(this["realm"]);
sb.Append(":");
sb.Append(Password);
var h1 = _md5.HashData( (ae.GetBytes(sb.ToString())).AsBuffer()).ToArray();
// Create the rest of A1 as stated in the RFC.
sb.Remove(0, sb.Length);
sb.Append(":");
sb.Append(this["nonce"]);
sb.Append(":");
sb.Append(_cnonce);
if (this["authzid"] != null)
{
sb.Append(":");
sb.Append(this["authzid"]);
}
var a1 = sb.ToString();
// Combine H1 and A1 into final A1
var ms = new MemoryStream();
ms.Write(h1, 0, 16);
var temp = ae.GetBytes(a1);
ms.Write(temp, 0, temp.Length);
ms.Seek(0, SeekOrigin.Begin);
h1 = _md5.HashData( ms.GetWindowsRuntimeBuffer() ).ToArray();
//Create A2
sb.Remove(0, sb.Length);
sb.Append("AUTHENTICATE:");
sb.Append(_digestUri);
if (this["qop"].CompareTo("auth") != 0)
{
sb.Append(":00000000000000000000000000000000");
}
var a2 = sb.ToString();
var h2 = _md5.HashData( (ae.GetBytes(a2)).AsBuffer() ).ToArray();
// Make A1 and A2 hex strings
var p1 = HexString(h1).ToLower();
var p2 = HexString(h2).ToLower();
// Combine all portions into the final response hex string
sb.Remove(0, sb.Length);
sb.Append(p1);
sb.Append(":");
sb.Append(this["nonce"]);
sb.Append(":");
sb.Append(_ncString);
sb.Append(":");
sb.Append(_cnonce);
sb.Append(":");
sb.Append(this["qop"]);
sb.Append(":");
sb.Append(p2);
var a3 = sb.ToString();
var h3 = _md5.HashData( (ae.GetBytes(a3)).AsBuffer() ).ToArray();
_responseHash = HexString(h3).ToLower();
}
示例13: TakePicture
public async Task<IBuffer> TakePicture()
{
if (_photoCaptureDevice == null && _cameraSemaphore.WaitOne(100))
return null;
if (_cameraSemaphore.WaitOne(100))
{
try
{
int angle = 0;
if (Orientation.HasFlag(PageOrientation.LandscapeLeft))
{
angle = (int)_photoCaptureDevice.SensorRotationInDegrees - 90;
}
else if (Orientation.HasFlag(PageOrientation.LandscapeRight))
{
angle = (int)_photoCaptureDevice.SensorRotationInDegrees + 90;
}
else // PageOrientation.PortraitUp
{
angle = (int)_photoCaptureDevice.SensorRotationInDegrees;
}
if (angle < 0) angle += 360;
if (_cameraLocation == CameraSensorLocation.Back)
{
_photoCaptureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, angle);
}
else
{
_photoCaptureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, -angle);
}
_photoCaptureDevice.SetProperty(KnownCameraGeneralProperties.SpecifiedCaptureOrientation, 0);
var cameraCaptureSequence = _photoCaptureDevice.CreateCaptureSequence(1);
var stream = new MemoryStream();
cameraCaptureSequence.Frames[0].CaptureStream = stream.AsOutputStream();
await _photoCaptureDevice.PrepareCaptureSequenceAsync(cameraCaptureSequence);
await cameraCaptureSequence.StartCaptureAsync();
IBuffer capturedPicture;
if (_cameraLocation == CameraSensorLocation.Back)
{
capturedPicture = stream.GetWindowsRuntimeBuffer();
}
else
{
capturedPicture = await JpegTools.FlipAndRotateAsync(stream.GetWindowsRuntimeBuffer(), FlipMode.Horizontal, Rotation.Rotate0, JpegOperation.AllowLossy);
}
using (var source = new StreamImageSource(capturedPicture.AsStream()))
{
var recipe = RecipeFactory.Current.CreatePipeline(source);
using (var renderer = new JpegRenderer(recipe))
{
capturedPicture = await renderer.RenderAsync();
}
if (recipe is IDisposable)
(recipe as IDisposable).Dispose();
}
return capturedPicture;
}
finally
{
_cameraSemaphore.Release();
}
}
return null;
}
示例14: SetPhotoFromEditedPage
private async void SetPhotoFromEditedPage(string FiledID)
{
MediaLibrary library = new MediaLibrary();
Picture photoFromLibrary = library.GetPictureFromToken(FiledID);
using (MemoryStream stream = new MemoryStream())
{
photoFromLibrary.GetImage().CopyTo(stream);
App.PhotoModel = new PhotoModel() { Buffer = stream.GetWindowsRuntimeBuffer() };
App.PhotoModel.Captured = true;
App.PhotoModel.Dirty = true;
Setup();
pgrAddress.Visibility = System.Windows.Visibility.Visible;
await RenderAsync();
pgrAddress.Visibility = System.Windows.Visibility.Collapsed;
}
}
示例15: Task_Completed
private void Task_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
if (Helpers.FileHelpers.IsValidPicture(e.OriginalFileName))
{
if (App.PhotoModel != null)
{
App.PhotoModel.Dispose();
App.PhotoModel = null;
GC.Collect();
}
using (MemoryStream stream = new MemoryStream())
{
e.ChosenPhoto.CopyTo(stream);
App.PhotoModel = new PhotoModel() { Buffer = stream.GetWindowsRuntimeBuffer() };
App.PhotoModel.Captured = (sender == _cameraCaptureTask);
App.PhotoModel.Dirty = App.PhotoModel.Captured;
}
Dispatcher.BeginInvoke(() => { NavigationService.Navigate(new Uri("/Pages/PhotoPage.xaml", UriKind.Relative)); });
}
else
{
MessageBox.Show(AppResources.App_MessageBox_UnsupportedImage_Message,
AppResources.App_MessageBox_UnsupportedImage_Caption, MessageBoxButton.OK);
}
}
}