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


C# WriteableBitmap.LoadAsync方法代码示例

本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.LoadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.LoadAsync方法的具体用法?C# WriteableBitmap.LoadAsync怎么用?C# WriteableBitmap.LoadAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.UI.Xaml.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.LoadAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenButton_Click

        private async void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            StorageFolder temp = ApplicationData.Current.LocalCacheFolder;
            StorageFile file = await temp.CreateFileAsync("current_image.png", CreationCollisionOption.ReplaceExisting);

            await cameraService.MediaCapture.CapturePhotoToStorageFileAsync(ImageEncodingProperties.CreateJpeg(), file);

            file = null;
            file = await temp.GetFileAsync("current_image.png");

            var wb = new WriteableBitmap(1, 1);
            await wb.LoadAsync(file);
            this.ImageCropper.SourceImage = wb;

            await cameraService.StopPreviewAsync();
            this.CameraPreview.Visibility = Visibility.Collapsed;
        }
开发者ID:RareNCool,项目名称:UWP-ImageCropper-,代码行数:17,代码来源:CameraPage.xaml.cs

示例2: OpenButton_Click

 private async void OpenButton_Click(object sender, RoutedEventArgs e)
 {
     FileOpenPicker openPicker = new FileOpenPicker();
     openPicker.ViewMode = PickerViewMode.Thumbnail;
     openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
     openPicker.FileTypeFilter.Add(".jpg");
     openPicker.FileTypeFilter.Add(".bmp");
     openPicker.FileTypeFilter.Add(".gif");
     openPicker.FileTypeFilter.Add(".png");
     StorageFile imgFile = await openPicker.PickSingleFileAsync();
     if (imgFile != null)
     {
         var wb = new WriteableBitmap(1,1);
         await wb.LoadAsync(imgFile);
         this.ImageCropper.SourceImage = wb;
     }
 }
开发者ID:RareNCool,项目名称:UWP-ImageCropper-,代码行数:17,代码来源:TemplatePage.xaml.cs

示例3: LoadTexture

        public async Task LoadTexture(string filename)
        {
            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            var texFile = await folder.GetFileAsync(filename);
            var properties = await texFile.Properties.GetImagePropertiesAsync();

            WriteableBitmap wbmp = new WriteableBitmap((Int32)properties.Width, (Int32)properties.Height);

            await wbmp.LoadAsync(texFile);

            byte[] pixels = new byte[wbmp.PixelWidth * wbmp.PixelHeight * 4];

            using (Stream pixelStream = wbmp.PixelBuffer.AsStream())
            {
                await pixelStream.ReadAsync(pixels, 0, pixels.Length);
            }
            wbmp.Invalidate();
            TexturePixels = new Vector3[wbmp.PixelHeight, wbmp.PixelWidth];
            int r = 0, c = 0;
            for (int i = 0; i < pixels.Length; i++)
            {


                TexturePixels[r, c] = new Vector3(pixels[i + 2], pixels[i + 1], pixels[i + 0]) / 255.0f;


                c = (c + 1) % wbmp.PixelWidth;

                if (c == 0)
                {
                    r = (r + 1) % wbmp.PixelHeight;

                }

                i += 3;

            }

            TexSize = new Vector2(wbmp.PixelWidth, wbmp.PixelHeight);

        }
开发者ID:GriffinLedingham,项目名称:RayTracer,代码行数:42,代码来源:FunkyTexture.cs

示例4: CropImage

        private async void CropImage(bool wide = false)
        {
            IsCropEnabled = false;
            try
            { 
                var img = wide ? _previewImageWide : _previewImageNormal;
                WriteableBitmap resizedBitmap = new WriteableBitmap(CropWidth, CropHeight);
                //if (img.UriSource == null)
                //await resizedBitmap.LoadAsync(_originaPickedStorageFile);
                /*else*/
                if (!img.UriSource.ToString().Contains("ms-appdata"))
                {
                    var imgFile = await SaveImage(img, wide);
                    await resizedBitmap.LoadAsync(imgFile);
                }
                else
                    await resizedBitmap.LoadAsync(await StorageFile.GetFileFromApplicationUriAsync(img.UriSource));

                if (wide)
                    resizedBitmap = resizedBitmap.Crop(CropLeftWide, CropTopWide, CropWidthWide + CropLeftWide, CropTopWide + CropHeightWide);
                else
                    resizedBitmap = resizedBitmap.Crop(CropLeft, CropTop, CropWidth + CropLeft, CropTop + CropHeight);

                var file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync($"_cropTemp{(wide ? "Wide" : "")}.png", CreationCollisionOption.GenerateUniqueName);

                if (wide)
                    _lastCroppedFileNameWide = file.Name;
                else
                    _lastCroppedFileName = file.Name;

                await resizedBitmap.SaveAsync(file, BitmapEncoder.PngEncoderId);

                if (wide)
                {
                    PreviewImageWide = new BitmapImage(new Uri($"ms-appdata:///temp/{file.Name}"));
                }
                else
                {
                    PreviewImageNormal = new BitmapImage(new Uri($"ms-appdata:///temp/{file.Name}"));
                    UndoCropVisibility = Visibility.Visible;
                }
                
            }
            catch (Exception)
            {
                UWPUtilities.GiveStatusBarFeedback("An error occured...");
            }
            IsCropEnabled = true;
        }
开发者ID:Mordonus,项目名称:MALClient,代码行数:49,代码来源:PinTileDialogViewModel.cs

示例5: CreateTriangles

        public async Task CreateTriangles(string filename, float scale, Vector3 position)
        {

            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var file = await folder.GetFileAsync(filename);
            var wholeFile = await FileIO.ReadTextAsync(file);

            int v = 0;
            int t = 0;
            int n = 0;
            string[] read = wholeFile.Split('\n');
            byte[] pixels = new byte[1];
            WriteableBitmap wbmp = null;
            Vector2 X = new Vector2(float.MaxValue, float.MinValue), Y = new Vector2(float.MaxValue, float.MinValue), Z = new Vector2(float.MaxValue, float.MinValue);

            FunkyTexture texture = new FunkyTexture();

            string mtlFilename = string.Empty;

            foreach (string s in read)
            {
                if (s.Length == 0) continue;
                if (s[0] == 'v' && s[1] == ' ')
                {
                    v++;
                    string[] temp = s.Split(' ');
                    float x = float.Parse(temp[1]);
                    if (x < X.X) X.X = x;
                    if (x > X.Y) X.Y = x;

                    float y = float.Parse(temp[2]);
                    if (y < Y.X) Y.X = y;
                    if (y > Y.Y) Y.Y = y;

                    float z = float.Parse(temp[3]);
                    if (z < Z.X) Z.X = z;
                    if (z > Z.Y) Z.Y = z;

                }
                else if (s[0] == 'v' && s[1] == 't')
                {
                    t++;
                }
                else if (s[0] == 'v' && s[1] == 'n')
                {
                    n++;
                }
                else if (s.Contains("mtllib"))
                {

                    mtlFilename = s.Split(' ')[1];
                    var mtlFile = await folder.GetFileAsync(mtlFilename);
                    var mtlText = await FileIO.ReadTextAsync(mtlFile);

                    foreach (string ms in mtlText.Trim().Split('\n'))
                    {
                        if (ms.Contains("map_Kd"))
                        {
                            string texFilename = ms.Split(' ')[1];

                            var texFile = await folder.GetFileAsync(texFilename);
                            var properties = await texFile.Properties.GetImagePropertiesAsync();

                            wbmp = new WriteableBitmap((Int32)properties.Width, (Int32)properties.Height);

                            await wbmp.LoadAsync(texFile);

                            pixels = new byte[wbmp.PixelWidth * wbmp.PixelHeight * 4];

                            using (Stream pixelStream = wbmp.PixelBuffer.AsStream())
                            {
                                await pixelStream.ReadAsync(pixels, 0, pixels.Length);
                            }
                            wbmp.Invalidate();
                            texture.TexturePixels = new Vector3[wbmp.PixelHeight, wbmp.PixelWidth];
                            int r = 0, c = 0;
                            for (int i = 0; i < pixels.Length; i++)
                            {

 
                           texture.TexturePixels[r, c] = new Vector3(pixels[i+2], pixels[i+1], pixels[i+0])/255.0f;


                                c = (c + 1) % wbmp.PixelWidth;

                                if (c == 0)
                                {
                                    r = (r + 1) % wbmp.PixelHeight;

                                }

                                i+=3;

                            }

                            texture.TexSize = new Vector2(wbmp.PixelWidth, wbmp.PixelHeight);

                        }
                    }
                }
//.........这里部分代码省略.........
开发者ID:GriffinLedingham,项目名称:RayTracer,代码行数:101,代码来源:objLoader.cs


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