• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IRandomAccessStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IRandomAccessStream的典型用法代码示例。如果您正苦于以下问题:C# IRandomAccessStream类的具体用法?C# IRandomAccessStream怎么用?C# IRandomAccessStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IRandomAccessStream类属于命名空间,在下文中一共展示了IRandomAccessStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: LoadSurfaceAsync

 public async Task LoadSurfaceAsync(ICanvasResourceCreator creator, IRandomAccessStream stream)
 {
     tempSurface = await CanvasBitmap.LoadAsync(creator, stream);
     bound = tempSurface.Bounds;
     center = tempSurface.Size.ToVector2() / 2;
     blur.Source = tempSurface;
 }
开发者ID:aurora-lzzp,项目名称:Aurora-Weather,代码行数:7,代码来源:BGBlur.cs


示例2: InternalSaveAsync

 /// <summary>
 /// Saves the file with fullFilePath, uses FileMode.Create, so file create time will be rewrited if needed
 /// If exception has occurred while writing the file, it will delete it
 /// </summary>
 /// <param name="fullFilePath">example: "\\image_cache\\213898adj0jd0asd</param>
 /// <param name="cacheStream">stream to write to the file</param>
 /// <returns>true if file was successfully written, false otherwise</returns>
 protected async virtual Task<bool> InternalSaveAsync(string fullFilePath, IRandomAccessStream cacheStream)
 {
     var storageFile = await SF.CreateFileAsync(fullFilePath, CreationCollisionOption.ReplaceExisting);
     using (IRandomAccessStream outputStream = await storageFile.OpenAsync(FileAccessMode.ReadWrite))
     {
         try
         {
             await RandomAccessStream.CopyAsync(
                 cacheStream.GetInputStreamAt(0L),
                 outputStream.GetOutputStreamAt(0L));
             return true;
         }
         catch
         {
             try
             {
                 // If file was not saved normally, we should delete it
                 await storageFile.DeleteAsync();
             }
             catch
             {
                 ImageLog.Log("[error] can not delete unsaved file: " + fullFilePath);
             }
         }
     }
     ImageLog.Log("[error] can not save cache to the: " + fullFilePath);
     return false;
 }
开发者ID:taojunfeng,项目名称:ImageLib.UWP,代码行数:35,代码来源:StorageCacheBase.cs


示例3: ResizeImageHard

        /// <summary>
        /// 改变图片的大小
        /// </summary>
        /// <param name="sourceStream">包含图片数据的流</param>
        /// <param name="expWidth">期望的宽度</param>
        /// <param name="expHeight">期望的高度</param>
        /// <returns></returns>
        public static async Task<IRandomAccessStream> ResizeImageHard(IRandomAccessStream sourceStream, uint expWidth,uint expHeight)
        {
            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);
            uint height = decoder.PixelHeight;
            uint weight = decoder.PixelWidth;

            uint destHeight = height > expHeight ? expHeight : height;
            uint destWeight = weight> expWidth? expWidth : weight;

            BitmapTransform transform = new BitmapTransform()
            {
                ScaledWidth = destWeight,
                ScaledHeight = destHeight
            };

            PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
                BitmapPixelFormat.Rgba8,
                BitmapAlphaMode.Straight,
                transform,
                ExifOrientationMode.IgnoreExifOrientation,
                ColorManagementMode.DoNotColorManage);

            var tempfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("temp.jpg", CreationCollisionOption.ReplaceExisting);
            IRandomAccessStream destStream = await tempfile.OpenAsync(FileAccessMode.ReadWrite);

            BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destStream);
            encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, transform.ScaledWidth, transform.ScaledHeight, 100, 100, pixelData.DetachPixelData());
            await encoder.FlushAsync();

            //把流的位置变为0,这样才能从头读出图片流
            destStream.Seek(0);

            return destStream;
        }
开发者ID:liqinghuang,项目名称:JP.Utils.UWP,代码行数:41,代码来源:BitmapImageHelper.cs


示例4: PlayStreamAsync

        public static async Task PlayStreamAsync(this MediaElement mediaElement, IRandomAccessStream stream, bool disposeStream = true)
        {
            // bool is irrelevant here, just using this to flag task completion.
            TaskCompletionSource<bool> taskCompleted = new TaskCompletionSource<bool>();

            // Note that the MediaElement needs to be in the UI tree for events like MediaEnded to fire.
            RoutedEventHandler endOfPlayHandler = (s, e) =>
            {
                if (disposeStream)
                    stream.Dispose();

                taskCompleted.SetResult(true);
            };

            mediaElement.MediaEnded += endOfPlayHandler;

            mediaElement.SetSource(stream, (stream as SpeechSynthesisStream).ContentType);
            mediaElement.Volume = 1;
            mediaElement.IsMuted = false;
            mediaElement.Play();

            await taskCompleted.Task;

            mediaElement.MediaEnded -= endOfPlayHandler;
        }
开发者ID:KonstantinKolesnik,项目名称:SmartHub,代码行数:25,代码来源:MediaElementExtensions.cs


示例5: CaptureToStreamAsync

        //Creates RenderTargetBitmap from UI Element
        async Task<RenderTargetBitmap> CaptureToStreamAsync(FrameworkElement uielement, IRandomAccessStream stream, Guid encoderId)
        {
            try
            {
                var renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(uielement);
                var pixels = await renderTargetBitmap.GetPixelsAsync();
                var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
                var encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
                encoder.SetPixelData(
                    BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Ignore,
                    (uint)renderTargetBitmap.PixelWidth,
                    (uint)renderTargetBitmap.PixelHeight,
                    logicalDpi,
                    logicalDpi,
                    /*pixels.ToArray()*/ null);

                await encoder.FlushAsync();
                return renderTargetBitmap;

            }
            catch
            {

            }

            return null;
        }
开发者ID:BilelTabakh,项目名称:TrackMeForWindowsPhone,代码行数:30,代码来源:ScreenShotShare.cs


示例6: ImageToBytes

        private async Task<byte[]> ImageToBytes(IRandomAccessStream sourceStream)
        {
            byte[] imageArray;

            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);

            var transform = new BitmapTransform { ScaledWidth = decoder.PixelWidth, ScaledHeight = decoder.PixelHeight };
            PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
                BitmapPixelFormat.Rgba8,
                BitmapAlphaMode.Straight,
                transform,
                ExifOrientationMode.RespectExifOrientation,
                ColorManagementMode.DoNotColorManage);

            using (var destinationStream = new InMemoryRandomAccessStream())
            {
                BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, destinationStream);
                encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, decoder.PixelWidth,
                    decoder.PixelHeight, 96, 96, pixelData.DetachPixelData());
                await encoder.FlushAsync();

                BitmapDecoder outputDecoder = await BitmapDecoder.CreateAsync(destinationStream);
                await destinationStream.FlushAsync();
                imageArray = (await outputDecoder.GetPixelDataAsync()).DetachPixelData();
            }
            return imageArray;
        }
开发者ID:orangpelupa,项目名称:PlayStation-App,代码行数:27,代码来源:AttachImageCommand.cs


示例7: UpdateImage

        public void UpdateImage(IRandomAccessStream rass)
        {

            storage["Picture"] = new ParseFile("Picture.jpg", rass.AsStreamForRead());

            this.RaisePropertyChanged("Picture");
        }
开发者ID:psotirov,项目名称:TelerikAcademyProjects,代码行数:7,代码来源:UpdatesModel.cs


示例8: InitializeAsync

 public async Task<ImageSource> InitializeAsync(CoreDispatcher dispatcher, IRandomAccessStream streamSource, CancellationTokenSource cancellationTokenSource)
 {
     byte[] bytes = new byte[streamSource.Size];
     await streamSource.ReadAsync(bytes.AsBuffer(), (uint)streamSource.Size, InputStreamOptions.None).AsTask(cancellationTokenSource.Token);
     var imageSource = WebpCodec.Decode(bytes);
     return imageSource;
 }
开发者ID:yyx290799684,项目名称:ImageLib.UWP,代码行数:7,代码来源:WebpDecoder.cs


示例9: GetImageFromFile

        /// <summary>
        /// Returns a Bitmap image for a give random access stream 
        /// </summary>
        /// <param name="stream">Random access stream for which the bitmap needs to be generated</param>
        /// <return Type="BitmapImage">Bitmap for the given stream</return>
        static async public Task<BitmapImage> GetImageFromFile(IRandomAccessStream stream)
        {
            BitmapImage bmp = new BitmapImage();

            await bmp.SetSourceAsync(stream);
            return bmp;
        }
开发者ID:oldnewthing,项目名称:old-Windows8-samples,代码行数:12,代码来源:Utils.cs


示例10: ReadIntoBuffer

 public static async Task<IBuffer> ReadIntoBuffer(IRandomAccessStream stream)
 {
     stream.Seek(0);
     var buffer = new Buffer((uint) stream.Size);
     await stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None);
     return buffer;
 }
开发者ID:joshholmes,项目名称:BulletTime,代码行数:7,代码来源:StorageIO.cs


示例11: UploadImgur

 public static async Task<ImgurEntity> UploadImgur(IRandomAccessStream fileStream)
 {
     try
     {
         var imageData = new byte[fileStream.Size];
         for (int i = 0; i < imageData.Length; i++)
         {
             imageData[i] = (byte)fileStream.AsStreamForRead().ReadByte();
         }
         var theAuthClient = new HttpClient();
         var request = new HttpRequestMessage(HttpMethod.Post, "https://api.imgur.com/3/image");
         request.Headers.Authorization = new AuthenticationHeaderValue("Client-ID", "e5c018ac1f4c157");
         var form = new MultipartFormDataContent();
         var t = new StreamContent(fileStream.AsStream());
         // TODO: See if this is the correct way to use imgur's v3 api. I can't see why we would still need to convert images to base64.
         string base64Img = Convert.ToBase64String(imageData);
         t.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
         form.Add(new StringContent(base64Img), @"image");
         form.Add(new StringContent("file"), "type");
         request.Content = form;
         HttpResponseMessage response = await theAuthClient.SendAsync(request);
         string responseString = await response.Content.ReadAsStringAsync();
         if (responseString == null) return null;
         var imgurEntity = JsonConvert.DeserializeObject<ImgurEntity>(responseString);
         return imgurEntity;
     }
     catch (WebException)
     {
     }
     catch (IOException)
     {
         return null;
     }
     return null;
 }
开发者ID:Ephemerial,项目名称:Awful-Forums-Reader,代码行数:35,代码来源:UploadManager.cs


示例12: Decrypt

        /// <summary>
        /// Decrypts the specified input stream.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="masterKey">The master key.</param>
        /// <param name="masterSeed">The master seed.</param>
        /// <param name="encryptionIV">The encryption initialization vector.</param>
        /// <returns>The decrypted buffer.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="input"/>, <paramref name="masterSeed"/>, <paramref name="masterKey"/>
        /// and <paramref name="encryptionIV"/> cannot be <c>null</c>.
        /// </exception>
        public static async Task<IInputStream> Decrypt(IRandomAccessStream input,
            IBuffer masterKey, IBuffer masterSeed, IBuffer encryptionIV)
        {
            if (input == null) throw new ArgumentNullException("input");
            if (masterSeed == null) throw new ArgumentNullException("masterSeed");
            if (masterKey == null) throw new ArgumentNullException("masterKey");
            if (encryptionIV == null) throw new ArgumentNullException("encryptionIV");

            var sha = HashAlgorithmProvider
                .OpenAlgorithm(HashAlgorithmNames.Sha256)
                .CreateHash();

            sha.Append(masterSeed);
            sha.Append(masterKey);

            var seed = sha.GetValueAndReset();
            var aes = SymmetricKeyAlgorithmProvider
                .OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7)
                .CreateSymmetricKey(seed);

            var buffer = WindowsRuntimeBuffer.Create(
                (int)(input.Size - input.Position));
            buffer = await input.ReadAsync(buffer, buffer.Capacity);
            buffer = CryptographicEngine.Decrypt(aes, buffer, encryptionIV);

            var stream = new InMemoryRandomAccessStream();
            await stream.WriteAsync(buffer);
            stream.Seek(0);

            return stream;
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:43,代码来源:FileFormat.cs


示例13: ConverterBitmapToTargetStreamAsync

		public async Task ConverterBitmapToTargetStreamAsync(IRandomAccessStream bitmapSourceStream, IRandomAccessStream saveTargetStream)
		{
			BitmapDecoder decoder = await BitmapDecoder.CreateAsync(bitmapSourceStream);
			// Scale image to appropriate size
			BitmapTransform transform = new BitmapTransform()
			{
				//ScaledWidth = Convert.ToUInt32(bi.PixelWidth),
				//ScaledHeight = Convert.ToUInt32(bi.PixelHeight) 
			};

			PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
				BitmapPixelFormat.Bgra8,    // WriteableBitmap uses BGRA format
				BitmapAlphaMode.Straight,
				transform,
				ExifOrientationMode.RespectExifOrientation, // This sample ignores Exif orientation
				ColorManagementMode.DoNotColorManage);

			var BitmapEncoderGuid = BitmapEncoder.PngEncoderId;

			BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoderGuid, saveTargetStream);

			encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
					  (uint)decoder.PixelWidth,
					  (uint)decoder.PixelHeight,
					  96.0,
					  96.0,
					  pixelData.DetachPixelData());
			await encoder.FlushAsync();
		}
开发者ID:waynebaby,项目名称:GreaterShareUWP,代码行数:29,代码来源:ConvertImageToPNGService.cs


示例14: GetThumbnailImage

        public async Task<IRandomAccessStream> GetThumbnailImage(IRandomAccessStream stream, int width, int height, bool smartCropping = true)
        {
            var response = await _client.GetThumbnailAsync(stream.AsStreamForRead(), width, height, smartCropping);

            var responseStream = new MemoryStream(response);
            return responseStream.AsRandomAccessStream();
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:7,代码来源:VisionApi.cs


示例15: ResizeImage

        /// <summary>
        /// 改变图片大小
        /// </summary>
        /// <param name="sourceStream">包含图片数据的数据流</param>
        /// <param name="scaleLong">如果图片长大于宽,那么此为改编后的长度,反之是改变后的高度</param>
        /// <returns></returns>
        public static async Task<IRandomAccessStream> ResizeImage(IRandomAccessStream sourceStream,uint scaleLong)
        {
            try
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);
                uint height = decoder.PixelHeight;
                uint weight = decoder.PixelWidth;

                double rate;
                uint destHeight = height;
                uint destWeight = weight;

                if (weight > height)
                {
                    rate = scaleLong / (double)weight;
                    destHeight = weight > scaleLong ? (uint)(rate * height) : height;
                    destWeight = scaleLong;
                }
                else
                {
                    rate = scaleLong / (double)height;
                    destWeight = height > scaleLong ? (uint)(rate * weight) : weight;
                    destHeight = scaleLong;
                }

                BitmapTransform transform = new BitmapTransform()
                {
                    ScaledWidth = destWeight,
                    ScaledHeight = destHeight
                };

                PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
                    BitmapPixelFormat.Rgba8,
                    BitmapAlphaMode.Straight,
                    transform,
                    ExifOrientationMode.IgnoreExifOrientation,
                    ColorManagementMode.DoNotColorManage);

                var folder = ApplicationData.Current.TemporaryFolder;
                var tempfile = await folder.CreateFileAsync("temp.jpg", CreationCollisionOption.GenerateUniqueName);
                IRandomAccessStream destStream = await tempfile.OpenAsync(FileAccessMode.ReadWrite);

                BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, destStream);
                encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight, transform.ScaledWidth, transform.ScaledHeight, 100, 100, pixelData.DetachPixelData());
                await encoder.FlushAsync();

                //REMEMBER
                destStream.Seek(0);

                await tempfile.DeleteAsync(StorageDeleteOption.PermanentDelete);

                return destStream;
            }
            catch(Exception e)
            {
                var task = ExceptionHelper.WriteRecordAsync(e, nameof(BitmapHandleHelper), nameof(ResizeImage));
                return null;
            }
        }
开发者ID:liqinghuang,项目名称:JP.Utils.UWP,代码行数:65,代码来源:BitmapImageHelper.cs


示例16: ConvertIRandomAccessStreamByte

 private static async Task<byte[]> ConvertIRandomAccessStreamByte(IRandomAccessStream stream)
 {
     DataReader read = new DataReader(stream.GetInputStreamAt(0));
     await read.LoadAsync((uint)stream.Size);
     byte[] temp = new byte[stream.Size];
     read.ReadBytes(temp);
     return temp;
 }
开发者ID:GuojieLin,项目名称:CnBlogs,代码行数:8,代码来源:ImageStorageHelper.cs


示例17: StorageImageFolder

 public static async Task<string> StorageImageFolder(IRandomAccessStream stream, string uri)
 {
     StorageFolder folder = await GetImageFolder();
     string image = RenameByMD5(uri) + ".png";
     StorageFile file = await folder.CreateFileAsync(image);
     await FileIO.WriteBytesAsync(file, await ConvertIRandomAccessStreamByte(stream));
     return file.Name;
 }
开发者ID:GuojieLin,项目名称:CnBlogs,代码行数:8,代码来源:ImageStorageHelper.cs


示例18: ProcessResponseOnHowAreYouImage

 private async Task<DialogStepResult> ProcessResponseOnHowAreYouImage(IRandomAccessStream image)
 {
     var prevalentEmotion = await _emotionApi.GetPrevalentEmotion(image);
     if (prevalentEmotion != "Normal")
         return new DialogStepResult(String.Format("You are full of {0}. What's up?", prevalentEmotion.ToLower()), new DialogStep(ProcessResponseOnWhatsUp, DidntCatchResponse));
     else
         return new DialogStepResult(")))", new DialogStep(FinalResponse, FinalResponse));
 }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:8,代码来源:HowAreYouDialog.cs


示例19: Process

        public async Task<string> Process(IRandomAccessStream image)
        {
            Check.Required<ArgumentNullException>(() => image != null);

            var result = await CurrentStep.Process(image);
            if (result.NextStep != null)
                CurrentStep = result.NextStep;
            return result.Response;
        }
开发者ID:evgri243,项目名称:pubic-demos,代码行数:9,代码来源:Dialog.cs


示例20: IRandomAccessStreamToStream

        public static async Task<Stream> IRandomAccessStreamToStream(IRandomAccessStream irStream)
        {

            byte[] pixels = await IRandomAccessStreamToByteArr(irStream);

            Stream stream = new MemoryStream(pixels);

            return stream;
        }
开发者ID:yjlintw,项目名称:YJToolkit,代码行数:9,代码来源:FileConvert.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IRandomGenerator类代码示例发布时间:2022-05-24
下一篇:
C# IRandom类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap