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);
        }
Example #2
0
        private void image_Tap(object sender, GestureEventArgs e)
        {
            Point             position = e.GetPosition(sender as UIElement);
            SpriteElementData elementByRelativePoint = this.CurrentDesc.GetElementByRelativePoint(new Point(position.X / this.Width, position.Y / this.FixedHeight));

            if (elementByRelativePoint == null)
            {
                return;
            }
            EventAggregator.Current.Publish((object)new SpriteElementTapEvent()
            {
                Data = elementByRelativePoint
            });
        }
Example #3
0
        private void image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            Point             position = e.GetPosition(sender as UIElement);
            Point             p        = new Point(((Point)@position).X / this.Width, ((Point)@position).Y / this.FixedHeight);
            SpriteElementData elementByRelativePoint = this.CurrentDesc.GetElementByRelativePoint(p);

            if (elementByRelativePoint == null)
            {
                return;
            }
            EventAggregator.Current.Publish(new SpriteElementTapEvent()
            {
                Data = elementByRelativePoint
            });
        }