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


C# WriteableBitmap.ForEach方法代码示例

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


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

示例1: SavePhoto

        public void SavePhoto()
        {
            var writeableBitmap = new WriteableBitmap(picture);
            resizedOverlay = OverlayedPicture.Resize(writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
            writeableBitmap.ForEach(Fill);
              // Create a virtual store and file stream. Check for duplicate tempJPEG files.
            string tempJPEG = CreateFileName();
            var myStore = IsolatedStorageFile.GetUserStoreForApplication();
            if (myStore.FileExists(tempJPEG)){
                myStore.DeleteFile(tempJPEG);
            }
            IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
            writeableBitmap.SaveJpeg(myFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
            myFileStream.Close();

            // Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
            myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
            string fileName = CreateFileName();
            new MediaLibrary().SavePictureToCameraRoll(fileName, myFileStream);
        }
开发者ID:KnownSubset,项目名称:Rephoto,代码行数:20,代码来源:CameraViewModel.cs

示例2: AdvGamePage

        public AdvGamePage()
        {
            InitializeComponent();

            var fileStream1 = Application.GetResourceStream(new Uri("TestImages/TestingUpper.png", UriKind.Relative));
            var s1 = new BitmapImage();
            using (var stream = fileStream1.Stream)
            {
                s1.SetSource(stream);
            }

            var upper = new WriteableBitmap(s1);

            var fileStream2 = Application.GetResourceStream(new Uri("TestImages/TestingLower.png", UriKind.Relative));
            var s2 = new BitmapImage();
            using (var stream = fileStream2.Stream)
            {
                s2.SetSource(stream);
            }

            var lower = new WriteableBitmap(s2);

            var upperEx = upper.GetBitmapContext();
            var lowerEx = lower.GetBitmapContext();

            UpperImage.Source = upper;
            LowerImage.Source = lower;

            upper.ForEach((x, y, color) =>
                {
                    var lowerColor = lower.GetPixel(x, y);
                    return new Color
                        {
                            R = (byte) (color.R - lowerColor.R),
                            G = (byte) (color.G - lowerColor.G),
                            B = (byte) (color.B - lowerColor.B),
                            A = color.A
                        };
                });
            upper.Invalidate();

            var changesPixels = new List<Point>();

            upper.ForEach((x, y, color) =>
                {
                    if (upper.GetPixel(x, y).R != 0)
                    {
                        lower.FillEllipseCentered(x, y, 10, 10, Colors.Red);
                        changesPixels.Add(new Point(x, y));
                    }

                    return color;
                });
            lower.Invalidate();

            //var indicator = new bool[480, 320];
            var startingPoint = changesPixels[0];
            var newPointToBeInvestigate = new List<Point> { startingPoint };
            changesPixels.Remove(startingPoint);
            //indicator[(int)startingPoint.X, (int)startingPoint.Y] = true;

            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            var i = 0;
            while (newPointToBeInvestigate.Count > 0 && i < newPointToBeInvestigate.Count)
            {
                var newPixels = changesPixels.Where(p => DistanceBetweenPoints(newPointToBeInvestigate[i], p)).ToList();

                foreach (var np in newPixels)
                {
                    changesPixels.Remove(np);
                    newPointToBeInvestigate.Add(np);
                }

                //foreach (var newP in newPixels.Where(newP => !indicator[(int)newP.X, (int)newP.Y]))
                //{
                //    indicator[(int)newP.X, (int)newP.Y] = true;
                //}

                i++;

            }
            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            foreach (var changeP in newPointToBeInvestigate)
            {
                lower.SetPixel((int)changeP.X, (int)changeP.Y, Colors.Green);
            }

            lower.Invalidate();
        }
开发者ID:NBitionDevelopment,项目名称:WindowsPhonePhotoHunt,代码行数:91,代码来源:AdvGamePage.xaml.cs


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