当前位置: 首页>>代码示例>>C#>>正文


C# MemoryStream.GetWindowsRuntimeBuffer方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:powerytg,项目名称:indulged-flickr,代码行数:35,代码来源:ProFXUtils.cs

示例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();
        }
开发者ID:powerytg,项目名称:indulged-flickr,代码行数:29,代码来源:ProFXCore.cs

示例3: GetServerChallenge

 private IBuffer GetServerChallenge()
 {
     using (var ms = new MemoryStream())
     {
         using (var sw = new StreamWriter(ms))
         {
             sw.Write(_serverChallenge);
         }
         return ms.GetWindowsRuntimeBuffer();
     }
 }
开发者ID:bospoort,项目名称:Win10UWPDemo,代码行数:11,代码来源:MainPage.xaml.cs

示例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());
        }
开发者ID:yukiyuki,项目名称:MyToolkit,代码行数:18,代码来源:MtSuspensionManager.cs

示例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);
            }
        }
开发者ID:powerytg,项目名称:indulged-flickr,代码行数:20,代码来源:BitmapBackgroundView.xaml.cs

示例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;
        }
开发者ID:JorgeCupi,项目名称:MusicLens,代码行数:38,代码来源:TombstoningHelper.cs

示例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);
//.........这里部分代码省略.........
开发者ID:JorgeCupi,项目名称:MusicLens,代码行数:101,代码来源:StreamRenderingHelper.cs

示例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);
                }
            }
        }
开发者ID:roachhd,项目名称:filter-explorer,代码行数:37,代码来源:PhotoPage.xaml.cs

示例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;
        }
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:41,代码来源:ViewFinder.xaml.cs

示例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());
            }
        }
开发者ID:ghstshdw,项目名称:PaperPhoto,代码行数:37,代码来源:MainPage.xaml.cs

示例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;
        }
开发者ID:KayNag,项目名称:LumiaImagingSDKSample,代码行数:20,代码来源:Effects.cs

示例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();
		}
开发者ID:jvthompson,项目名称:xmpp,代码行数:85,代码来源:MD5Processor.cs

示例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;
        }
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:75,代码来源:LIve.xaml.cs

示例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;
            }
        }
开发者ID:JorgeCupi,项目名称:MusicLens,代码行数:19,代码来源:PhotoPage.xaml.cs

示例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);
                }
            }
        }
开发者ID:JorgeCupi,项目名称:MusicLens,代码行数:32,代码来源:StreamPage.xaml.cs


注:本文中的System.IO.MemoryStream.GetWindowsRuntimeBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。