private bool CreateEmojiSprites(SpritesPack pack)
        {
            Stopwatch            stopwatch    = Stopwatch.StartNew();
            List <EmojiDataItem> allDataItems = EmojiDataItem.GetAllDataItems();
            int             num1             = EmojiConstants.ColumnsCountVerticalOrientation * EmojiConstants.VerticalSpriteRowsCount;
            int             num2             = 0;
            string          str1             = "emojiSpriteVertical" + this.IsDarkTheme.ToString() + ".jpg";
            SolidColorBrush backgroundColor1 = Application.Current.Resources["PhoneMenuBackgroundBrush"] as SolidColorBrush;
            IEnumerator <IEnumerable <EmojiDataItem> > enumerator1 = allDataItems.Partition <EmojiDataItem>(num1).GetEnumerator();

            try
            {
                while (((IEnumerator)enumerator1).MoveNext())
                {
                    IEnumerable <EmojiDataItem> current = enumerator1.Current;
                    SpriteDescription           sprite  = SpriteCreatorHelper.TryCreateSprite(num1, (List <string>)Enumerable.ToList <string>(Enumerable.Select <EmojiDataItem, string>(current, (Func <EmojiDataItem, string>)(d => d.Uri.OriginalString))), (List <string>)Enumerable.ToList <string>(Enumerable.Select <EmojiDataItem, string>(current, (Func <EmojiDataItem, string>)(d => d.String))), num2.ToString() + str1, EmojiConstants.ColumnsCountVerticalOrientation, EmojiConstants.EmojiWidthInPixels, EmojiConstants.EmojiHeightInPixels, EmojiConstants.VerticalSpriteWidthInPixels, EmojiConstants.VerticalSpriteHeightInPixels, backgroundColor1);
                    ++num2;
                    if (sprite == null)
                    {
                        return(false);
                    }
                    pack.SpritesVertical.Add(sprite);
                }
            }
            finally
            {
                if (enumerator1 != null)
                {
                    ((IDisposable)enumerator1).Dispose();
                }
            }
            int    num3 = EmojiConstants.ColumnsCountHorizontalOrientation * EmojiConstants.HorizontalSpriteRowsCount;
            int    num4 = 0;
            string str2 = "emojiSprteHorizontal " + this.IsDarkTheme.ToString() + ".jpg";
            IEnumerator <IEnumerable <EmojiDataItem> > enumerator2 = allDataItems.Partition <EmojiDataItem>(num3).GetEnumerator();

            try
            {
                while (((IEnumerator)enumerator2).MoveNext())
                {
                    IEnumerable <EmojiDataItem> current = enumerator2.Current;
                    SpriteDescription           sprite  = SpriteCreatorHelper.TryCreateSprite(num3, (List <string>)Enumerable.ToList <string>(Enumerable.Select <EmojiDataItem, string>(current, (Func <EmojiDataItem, string>)(d => d.Uri.OriginalString))), (List <string>)Enumerable.ToList <string>(Enumerable.Select <EmojiDataItem, string>(current, (Func <EmojiDataItem, string>)(d => d.String))), num4.ToString() + str2, EmojiConstants.ColumnsCountHorizontalOrientation, EmojiConstants.EmojiWidthInPixels, EmojiConstants.EmojiHeightInPixels, EmojiConstants.HorizontalSpriteWidthInPixels, EmojiConstants.HorizontalSpriteHeightInPixels, backgroundColor1);
                    ++num4;
                    if (sprite == null)
                    {
                        return(false);
                    }
                    pack.SpritesHorizontal.Add(sprite);
                }
            }
            finally
            {
                if (enumerator2 != null)
                {
                    ((IDisposable)enumerator2).Dispose();
                }
            }
            stopwatch.Stop();
            return(true);
        }
 private void AddSprites(EmojiSpritesCreator eSpC)
 {
   Execute.ExecuteOnUIThread((Action) (() =>
   {
     SpritesPack spritesPack = eSpC.SpritesPack;
     List<SpriteDescription> spritesVertical = spritesPack.SpritesVertical;
     List<SpriteDescription> spritesHorizontal = spritesPack.SpritesHorizontal;
     this.myPanel.ClearItems();
     List<IVirtualizable> virtualizableList = new List<IVirtualizable>();
     for (int index = 0; index < spritesHorizontal.Count; ++index)
     {
       SpriteDescription vertSpriteDesc;
       if (index >= spritesVertical.Count)
         vertSpriteDesc = new SpriteDescription()
         {
           SpritePath = "",
           Elements = new List<SpriteElementData>()
         };
       else
         vertSpriteDesc = spritesVertical[index];
       SpriteDescription horSpriteDesc = spritesHorizontal[index];
       int num = this.IsHorizontal ? 1 : 0;
       SpriteItem spriteItem = new SpriteItem(vertSpriteDesc, horSpriteDesc, num != 0);
       if (index == 0)
         spriteItem.Margin = new Thickness(0.0, 6.0, 0.0, 0.0);
       virtualizableList.Add((IVirtualizable) spriteItem);
     }
     this.myPanel.AddItems((IEnumerable<IVirtualizable>) virtualizableList);
   }));
 }
        public static SpriteDescription TryCreateSprite(int maxElementsCount, List <string> originalUris, List <string> elementCodes, string saveResultUri1, int columnsCount, int widthOfOneItemInPixels, int heightOfOneItemInPixels, int widthInPixels, int heightInPixels, SolidColorBrush backgroundColor1)
        {
            SpriteDescription spriteDescription = new SpriteDescription();

            try
            {
                spriteDescription.WidthInPixels  = widthInPixels;
                spriteDescription.HeightInPixels = heightInPixels;
                spriteDescription.SpritePath     = saveResultUri1;
                spriteDescription.Elements       = new List <SpriteElementData>();
                WriteableBitmap writeableBitmap1 = new WriteableBitmap(widthInPixels, heightInPixels);
                WriteableBitmap writeableBitmap2 = writeableBitmap1;
                Canvas          canvas           = new Canvas();
                SolidColorBrush solidColorBrush  = backgroundColor1;
                ((Panel)canvas).Background = ((Brush)solidColorBrush);
                double num1 = (double)widthInPixels;
                ((FrameworkElement)canvas).Width = num1;
                double num2 = (double)heightInPixels;
                ((FrameworkElement)canvas).Height = num2;
                // ISSUE: variable of the null type

                writeableBitmap2.Render((UIElement)canvas, null);
                writeableBitmap1.Invalidate();
                int num3   = (int)Math.Ceiling((double)maxElementsCount / (double)columnsCount);
                int num4   = widthInPixels / columnsCount;
                int num5   = heightInPixels / num3;
                int num6   = (num4 - widthOfOneItemInPixels) / 2;
                int num7   = (num5 - heightOfOneItemInPixels) / 2;
                int height = 0;
                for (int index = 0; index < originalUris.Count; ++index)
                {
                    int    num8        = index % columnsCount * num4;
                    int    num9        = index / columnsCount * num5;
                    string originalUri = originalUris[index];
                    SpriteCreatorHelper.WriteImageToBitmap(writeableBitmap1, originalUri, num8 + num6, num9 + num7, widthOfOneItemInPixels, heightOfOneItemInPixels);
                    height = num9 + num5;
                    SpriteElementData spriteElementData = new SpriteElementData()
                    {
                        Position = new Rect((double)num8, (double)num9, (double)num4, (double)num5), ElementCode = elementCodes[index]
                    };
                    spriteDescription.Elements.Add(spriteElementData);
                }
                if (height < ((BitmapSource)writeableBitmap1).PixelHeight - 1)
                {
                    writeableBitmap1 = writeableBitmap1.Crop(0, 0, ((BitmapSource)writeableBitmap1).PixelWidth, height);
                    spriteDescription.HeightInPixels = height;
                }
                using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream storageFileStream = storeForApplication.OpenFile(saveResultUri1, FileMode.OpenOrCreate, FileAccess.Write))
                        Extensions.SaveJpeg(writeableBitmap1, (Stream)storageFileStream, spriteDescription.WidthInPixels, spriteDescription.HeightInPixels, 0, 90);
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(spriteDescription);
        }
Exemple #4
0
 public SpriteItem(SpriteDescription vertSpriteDesc, SpriteDescription horSpriteDesc, bool isHorizontal)
     : base(0.0)
 {
     this._vertSpriteDescription = vertSpriteDesc;
     this._horSpriteDescription  = horSpriteDesc;
     this._verticalWidth         = (double)vertSpriteDesc.WidthInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._horizontalWidth       = (double)horSpriteDesc.WidthInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._verticalHeight        = (double)vertSpriteDesc.HeightInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._horizontalHeight      = (double)horSpriteDesc.HeightInPixels * 100.0 / (double)ScaleFactor.GetRealScaleFactor();
     this._isHorizontal          = isHorizontal;
     this.Width = this._isHorizontal ? this._horizontalWidth : this._verticalWidth;
 }
        private bool CreateEmojiSprites(SpritesPack pack)
        {
            Stopwatch            stopwatch    = Stopwatch.StartNew();
            List <EmojiDataItem> allDataItems = EmojiDataItem.GetAllDataItems();
            int             num1             = EmojiConstants.ColumnsCountVerticalOrientation * EmojiConstants.VerticalSpriteRowsCount;
            int             num2             = 0;
            string          str1             = "emojiSpriteVertical" + this.IsDarkTheme.ToString() + ".jpg";
            SolidColorBrush backgroundColor1 = Application.Current.Resources["PhoneMenuBackgroundBrush"] as SolidColorBrush;

            foreach (IEnumerable <EmojiDataItem> source in allDataItems.Partition <EmojiDataItem>(num1))
            {
                SpriteDescription sprite = SpriteCreatorHelper.TryCreateSprite(num1, source.Select <EmojiDataItem, string>((Func <EmojiDataItem, string>)(d => d.Uri.OriginalString)).ToList <string>(), source.Select <EmojiDataItem, string>((Func <EmojiDataItem, string>)(d => d.String)).ToList <string>(), num2.ToString() + str1, EmojiConstants.ColumnsCountVerticalOrientation, EmojiConstants.EmojiWidthInPixels, EmojiConstants.EmojiHeightInPixels, EmojiConstants.VerticalSpriteWidthInPixels, EmojiConstants.VerticalSpriteHeightInPixels, backgroundColor1);
                ++num2;
                if (sprite == null)
                {
                    return(false);
                }
                pack.SpritesVertical.Add(sprite);
            }
            int    num3 = EmojiConstants.ColumnsCountHorizontalOrientation * EmojiConstants.HorizontalSpriteRowsCount;
            int    num4 = 0;
            string str2 = "emojiSprteHorizontal " + this.IsDarkTheme.ToString() + ".jpg";

            foreach (IEnumerable <EmojiDataItem> source in allDataItems.Partition <EmojiDataItem>(num3))
            {
                SpriteDescription sprite = SpriteCreatorHelper.TryCreateSprite(num3, source.Select <EmojiDataItem, string>((Func <EmojiDataItem, string>)(d => d.Uri.OriginalString)).ToList <string>(), source.Select <EmojiDataItem, string>((Func <EmojiDataItem, string>)(d => d.String)).ToList <string>(), num4.ToString() + str2, EmojiConstants.ColumnsCountHorizontalOrientation, EmojiConstants.EmojiWidthInPixels, EmojiConstants.EmojiHeightInPixels, EmojiConstants.HorizontalSpriteWidthInPixels, EmojiConstants.HorizontalSpriteHeightInPixels, backgroundColor1);
                ++num4;
                if (sprite == null)
                {
                    return(false);
                }
                pack.SpritesHorizontal.Add(sprite);
            }
            stopwatch.Stop();
            return(true);
        }