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


C# WriteableBitmap.SetSource方法代码示例

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


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

示例1: LimitImageSize

        private static Stream LimitImageSize(Stream imageStream, double imageMaxDiagonalSize)
        {
            // In order to determine the size of the image we will transfer it to a writable bitmap.
            WriteableBitmap wb = new WriteableBitmap(1, 1);
            wb.SetSource(imageStream);

            // Check if we need to scale it down.
            double imageDiagonalSize = Math.Sqrt(wb.PixelWidth * wb.PixelWidth + wb.PixelHeight * wb.PixelHeight);
            if (imageDiagonalSize > imageMaxDiagonalSize)
            {
                // Calculate the new image size that corresponds to imageMaxDiagonalSize for the
                // diagonal size and that preserves the aspect ratio.
                int newWidth = (int)(wb.PixelWidth * imageMaxDiagonalSize / imageDiagonalSize);
                int newHeight = (int)(wb.PixelHeight * imageMaxDiagonalSize / imageDiagonalSize);

                Stream resizedStream = new MemoryStream();
                Extensions.SaveJpeg(wb, resizedStream, newWidth, newHeight, 0, 100);

                return resizedStream;
            }
            else
            {
                // No need to scale down. The image diagonal is less than or equal to imageMaxSizeDiagonal.
                return imageStream;
            }
        }
开发者ID:mbmccormick,项目名称:Carded,代码行数:26,代码来源:MainPage.xaml.cs

示例2: Button_Click_1

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                PhotoChooserTask photoChooserTask           = new PhotoChooserTask();
                photoChooserTask.Completed += (ee,s)=>
                {
                    //DirectX context should be recreate before cereate the texture
                    Dispatcher.BeginInvoke(() =>
                   {
                       WriteableBitmap bmp = new WriteableBitmap(1,1);
                       bmp.SetSource(s.ChosenPhoto);
  
                       m_d3dInterop.CreateTexture(bmp.Pixels, bmp.PixelWidth, bmp.PixelHeight);
                       MessageBox.Show("Picture loaded with c#");
                   });


                };

                photoChooserTask.Show();

            }
            catch(Exception exp)
                {
                }
        }
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:27,代码来源:MainPage.xaml.cs

示例3: resizeImage

 // call by reference
 public static void resizeImage(ref WriteableBitmap bmp)
 {
     // TODO: memory management
     // we have 2 options
     // i) use "using" statement
     // ii) dispose of object "ms" before the method finishes (**check bmp1 as ms is set as it's source )
     MemoryStream ms = new MemoryStream();
     int h, w;
     if (bmp.PixelWidth > bmp.PixelHeight)
     {
         double aspRatio = bmp.PixelWidth / (double)bmp.PixelHeight;
         double hh, ww;
         hh = (640.0 / aspRatio);
         ww = hh * aspRatio;
         h = (int)hh;
         w = (int)ww;
     }
     else
     {
         double aspRatio = bmp.PixelHeight / (double)bmp.PixelWidth;
         double hh, ww;
         hh = (480.0 / aspRatio);
         ww = hh * aspRatio;
         h = (int)hh;
         w = (int)ww;
     }
     bmp.SaveJpeg(ms, w, h, 0, 100);
     bmp.SetSource(ms);
 }
开发者ID:jaydeep17,项目名称:CameraTest7,代码行数:30,代码来源:Utils.cs

示例4: task_Completed

        void task_Completed(object sender, PhotoResult e)
        {
            if(e.TaskResult == TaskResult.OK)
            {

                var bmp = new WriteableBitmap(0,0);
                bmp.SetSource(e.ChosenPhoto);

                var bmpres = new WriteableBitmap(bmp.PixelWidth,bmp.PixelHeight);

                var txt = new WindowsPhoneControl1();
                txt.Text = txtInput.Text;
                txt.FontSize = 36 * bmpres.PixelHeight / 480;
                txt.Width = bmpres.PixelWidth;
                txt.Height = bmpres.PixelHeight;

                //should call Measure and  when uicomponent is not in visual tree
                txt.Measure(new Size(bmpres.PixelWidth, bmpres.PixelHeight));
                txt.Arrange(new Rect(0, 0, bmpres.PixelWidth, bmpres.PixelHeight));

                bmpres.Render(new Image() { Source = bmp }, null);
                bmpres.Render(txt, null);

                bmpres.Invalidate();
                display.Source = bmpres;

            }
        }
开发者ID:Nokia-Developer-Community-Projects,项目名称:wp8-sample,代码行数:28,代码来源:MainPage.xaml.cs

示例5: assertCorrectImage2result

      private static void assertCorrectImage2result(String path, ExpandedProductParsedResult expected)
      {
         RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

         if (!File.Exists(path))
         {
            // Support running from project root too
            path = Path.Combine("..\\..\\..\\Source", path);
         }

#if !SILVERLIGHT
         var image = new Bitmap(Image.FromFile(path));
#else
         var image = new WriteableBitmap(0, 0);
         image.SetSource(File.OpenRead(path));
#endif
         BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BitmapLuminanceSource(image)));
         int rowNumber = binaryMap.Height / 2;
         BitArray row = binaryMap.getBlackRow(rowNumber, null);

         Result theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
         Assert.IsNotNull(theResult);

         Assert.AreEqual(BarcodeFormat.RSS_EXPANDED, theResult.BarcodeFormat);

         ParsedResult result = ResultParser.parseResult(theResult);

         Assert.AreEqual(expected, result);
      }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:29,代码来源:RSSExpandedImage2resultTestCase.cs

示例6: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ApplicationBar.Opacity = 0.5;
            if (this.NavigationContext.QueryString.ContainsKey("nid"))
            {
                var nid = Int32.Parse(this.NavigationContext.QueryString["nid"]);
                Capitulo c;

                if (AU.Instance.Capitulos.TryGetValue(nid, out c))
                {
                    PageTitle.Text = c.Nombre;
                    sinopsis.Text = c.TextoNoti;
                    textAutor.Text = c.NotiAutor;
                    textFecha.Text = c.ReleaseDate.ToString();
                    var i = 0;

                    serieId = c.Serie;
                    foreach (String file in c.Imagenes)
                    {
                        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                        {

                            if (myIsolatedStorage.FileExists(file))
                            {
                                using (var imageStream = myIsolatedStorage.OpenFile(file, FileMode.Open, FileAccess.Read))
                                {
                                    WriteableBitmap temp = new WriteableBitmap(0, 0);
                                    try
                                    {
                                        Image image1 = new Image();
                                        WriteableBitmap aux = new WriteableBitmap(0, 0);
                                        aux.SetSource(imageStream);
                                        image1.Source = (ImageSource)aux;
                                        image1.HorizontalAlignment = HorizontalAlignment.Left;
                                        image1.VerticalAlignment = VerticalAlignment.Top;
                                        image1.Stretch = Stretch.Uniform;
                                        ColumnDefinition colDef3 = new ColumnDefinition();
                                        imagenes.ColumnDefinitions.Add(colDef3);
                                        Grid.SetColumn(image1, i);
                                        i++;
                                        imagenes.Children.Add(image1);


                                    }
                                    catch (ArgumentException ae)
                                    {

                                    }

                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // I use this condition to handle creating new items.
            }
        }
开发者ID:awayo,项目名称:AUWP7,代码行数:60,代码来源:DetalleNoticia.xaml.cs

示例7: toWriteableBitmap

        public static WriteableBitmap toWriteableBitmap(Stream stream, int pixelWidth, int pixelHeight) {
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.SetSource(stream);

            WriteableBitmap bitmap = new WriteableBitmap(pixelWidth, pixelWidth);
            bitmap.SetSource(stream);
            return bitmap;
        }
开发者ID:lintghi,项目名称:puzzle,代码行数:8,代码来源:ImageUtils.cs

示例8: BytesToImage

 public BitmapImage BytesToImage(byte[] array, int width, int height)
 {
     WriteableBitmap result = new WriteableBitmap(width, height);
     MemoryStream ms = new MemoryStream();
     ms.Write(array, 0, array.Length);
     result.SetSource(ms);
     BitmapImage bitmapImage = new BitmapImage();
     bitmapImage.SetSource(ms);
     return bitmapImage;
 }
开发者ID:vit2005,项目名称:Multitier-Project,代码行数:10,代码来源:Imager.cs

示例9: ReadImageFromIsolatedStorage

 public static WriteableBitmap ReadImageFromIsolatedStorage(string imageName, int width, int height)
 {
     using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (var fileStream = isoStore.OpenFile(imageName, FileMode.Open, FileAccess.Read))
         {
             var bitmap = new WriteableBitmap(width, height);
             bitmap.SetSource(fileStream);
             return bitmap;
         }
     }
 }
开发者ID:radu-ungureanu,项目名称:Grimacizer,代码行数:12,代码来源:Helpers.cs

示例10: ToBitmapImageAsync

        public async static Task<WriteableBitmap> ToBitmapImageAsync(this Stream imageStream, Tuple<int, int> downscale, bool useDipUnits, InterpolationMode mode, ImageInformation imageInformation = null)
        {
            if (imageStream == null)
                return null;

            using (IRandomAccessStream image = new RandomStream(imageStream))
            {
                if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
                {
                    using (var downscaledImage = await image.ResizeImage(downscale.Item1, downscale.Item2, mode, useDipUnits, imageInformation).ConfigureAwait(false))
                    {
                        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(downscaledImage);
                        downscaledImage.Seek(0);
                        WriteableBitmap resizedBitmap = null;

                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                        {
                            resizedBitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                            using (var s = downscaledImage.AsStream())
                            {
                                resizedBitmap.SetSource(s);
                            }
                        });

                        return resizedBitmap;
                    }
                }
                else
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);
                    image.Seek(0);
                    WriteableBitmap bitmap = null;

                    if (imageInformation != null)
                    {
                        imageInformation.SetCurrentSize((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                        imageInformation.SetOriginalSize((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                    }

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                    {
                        bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                        bitmap.SetSource(imageStream);
                    });

                    return bitmap;
                }
            }
        }
开发者ID:CaLxCyMru,项目名称:FFImageLoading,代码行数:49,代码来源:ImageExtensions.cs

示例11: CreateDeadTileBitmap

        public void CreateDeadTileBitmap()
        {
            // load your image
            StreamResourceInfo info = Application.GetResourceStream(new Uri(DEAD_TILE, UriKind.Relative));
            // create source bitmap for Image control (image is assumed to be alread 173x173)
            WriteableBitmap wbmp = new WriteableBitmap(173, 173);
            wbmp.SetSource(info.Stream);

            // save image to isolated storage
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // use of "/Shared/ShellContent/" folder is mandatory!
                using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/Tile.jpg", System.IO.FileMode.Create, isf))
                {
                    wbmp.SaveJpeg(imageStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
                }
            }
        }
开发者ID:rsmallr,项目名称:CWBWeather_WP,代码行数:18,代码来源:TileUpdateWorker.cs

示例12: loadImage

      private static WriteableBitmap loadImage(String fileName)
#endif
      {
         String file = BASE_IMAGE_PATH + fileName;
         if (!File.Exists(file))
         {
            // try starting with 'core' since the test base is often given as the project root
            file = "..\\..\\..\\Source\\" + BASE_IMAGE_PATH + fileName;
         }
         Assert.IsTrue(File.Exists(file), "Please run from the 'core' directory");
#if !SILVERLIGHT
         return (Bitmap)Bitmap.FromFile(file);
#else
         var wb = new WriteableBitmap(0, 0);
         wb.SetSource(File.OpenRead(file));
         return wb;
#endif
      }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:18,代码来源:QRCodeWriterTestCase.cs

示例13: ToBitmapImageAsync

        public async static Task<WriteableBitmap> ToBitmapImageAsync(this byte[] imageBytes, Tuple<int, int> downscale, InterpolationMode mode)
        {
            if (imageBytes == null)
                return null;

            using (var imageStream = imageBytes.AsBuffer().AsStream())
            using (IRandomAccessStream image = new RandomStream(imageStream))
            {
                if (downscale != null && (downscale.Item1 > 0 || downscale.Item2 > 0))
                {
                    using (var downscaledImage = await image.ResizeImage((uint)downscale.Item1, (uint)downscale.Item2, mode).ConfigureAwait(false))
                    {
                        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(downscaledImage);
                        downscaledImage.Seek(0);
                        WriteableBitmap resizedBitmap = null;

                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                        {
                            resizedBitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                            using (var s = downscaledImage.AsStream())
                            {
                                resizedBitmap.SetSource(s);
                            }
                        });

                        return resizedBitmap;
                    }
                }
                else
                {
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(image);
                    image.Seek(0);
                    WriteableBitmap bitmap = null;

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                    {
                        bitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
                        bitmap.SetSource(imageStream);
                    });

                    return bitmap;
                }
            }
        }
开发者ID:martb1n,项目名称:FFImageLoading,代码行数:44,代码来源:ImageExtensions.cs

示例14: testFindFinderPatterns

      public void testFindFinderPatterns()
      {
         RSSExpandedReader rssExpandedReader = new RSSExpandedReader();

         String path = "test/data/blackbox/rssexpanded-1/2.png";

         if (!File.Exists(path))
         {
            // Support running from project root too
            path = Path.Combine("..\\..\\..\\Source", path);
         }

#if !SILVERLIGHT
         var image = new Bitmap(Image.FromFile(path));
#else
         var image = new WriteableBitmap(0, 0);
         image.SetSource(File.OpenRead(path));
#endif
         BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BitmapLuminanceSource(image)));
         int rowNumber = binaryMap.Height / 2;
         BitArray row = binaryMap.getBlackRow(rowNumber, null);
         List<ExpandedPair> previousPairs = new List<ExpandedPair>();

         ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
         previousPairs.Add(pair1);
         FinderPattern finderPattern = pair1.FinderPattern;
         Assert.IsNotNull(finderPattern);
         Assert.AreEqual(0, finderPattern.Value);

         ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
         previousPairs.Add(pair2);
         finderPattern = pair2.FinderPattern;
         Assert.IsNotNull(finderPattern);
         Assert.AreEqual(1, finderPattern.Value);

         ExpandedPair pair3 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
         previousPairs.Add(pair3);
         finderPattern = pair3.FinderPattern;
         Assert.IsNotNull(finderPattern);
         Assert.AreEqual(1, finderPattern.Value);

         //   the previous was the last pair
         Assert.IsNull(rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber));
      }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:44,代码来源:RSSExpandedInternalTestCase.cs

示例15: btnDecoderOpen_Click

 private void btnDecoderOpen_Click(object sender, RoutedEventArgs e)
 {
    var dlg = new OpenFileDialog();
    dlg.Filter = "PNG (*.png)|*.png";
    if (dlg.ShowDialog().GetValueOrDefault(false))
    {
       try
       {
          currentBarcode = new WriteableBitmap(0, 0);
          using (var stream = dlg.File.OpenRead())
          {
             currentBarcode.SetSource(stream);
          }
          imgDecoderBarcode.Source = currentBarcode;
       }
       catch (Exception exc)
       {
          txtDecoderContent.Text = exc.Message;
       }
    }
 }
开发者ID:Bogdan-p,项目名称:ZXing.Net,代码行数:21,代码来源:MainPage.xaml.cs


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