Ejemplo n.º 1
0
        public static ImageSource GetChat(Chat chat, int side)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    if (chat.Type is ChatTypePrivate privata)
                    {
                        PlaceholderImageHelper.Current.DrawProfilePlaceholder(InitialNameStringConverter.Convert(chat), _colorsTop[Math.Abs(privata.UserId % _colors.Length)], _colorsBottom[Math.Abs(privata.UserId % _colors.Length)], stream);
                    }
                    else if (chat.Type is ChatTypeSecret secret)
                    {
                        PlaceholderImageHelper.Current.DrawProfilePlaceholder(InitialNameStringConverter.Convert(chat), _colorsTop[Math.Abs(secret.UserId % _colors.Length)], _colorsBottom[Math.Abs(secret.UserId % _colors.Length)], stream);
                    }
                    else if (chat.Type is ChatTypeBasicGroup basic)
                    {
                        PlaceholderImageHelper.Current.DrawProfilePlaceholder(InitialNameStringConverter.Convert(chat), _colorsTop[Math.Abs(basic.BasicGroupId % _colors.Length)], _colorsBottom[Math.Abs(basic.BasicGroupId % _colors.Length)], stream);
                    }
                    else if (chat.Type is ChatTypeSupergroup super)
                    {
                        PlaceholderImageHelper.Current.DrawProfilePlaceholder(InitialNameStringConverter.Convert(chat), _colorsTop[Math.Abs(super.SupergroupId % _colors.Length)], _colorsBottom[Math.Abs(super.SupergroupId % _colors.Length)], stream);
                    }

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Ejemplo n.º 2
0
        public static ImageSource GetNameForChat(string title, int side, int color = 5)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.Current.DrawProfilePlaceholder(InitialNameStringConverter.Convert(title), _colorsTop[Math.Abs(color % _colors.Length)], _colorsBottom[Math.Abs(color % _colors.Length)], stream);
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Ejemplo n.º 3
0
        public static ImageSource GetChat(ChatInviteLinkInfo chat, int side)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.Current.DrawProfilePlaceholder(InitialNameStringConverter.Convert(chat), _colorsTop[5], _colorsBottom[5], stream);
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Ejemplo n.º 4
0
        public static ImageSource GetChat(ChatInviteLinkInfo chat, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[0], InitialNameStringConverter.Convert(chat), stream);
                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Ejemplo n.º 5
0
        public static ImageSource GetUser(User user, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[Math.Abs(user.Id % _colors.Length)], InitialNameStringConverter.Convert(user), stream);
                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Ejemplo n.º 6
0
        public static ImageSource GetNameForUser(string name, int side, int color = 5)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[color], InitialNameStringConverter.Convert((object)name), stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Ejemplo n.º 7
0
        private async void SetProfilePlaceholder(object value, string group, int id, string name)
        {
            if (PHASE_PLACEHOLDER >= Phase)
            {
                Phase = PHASE_PLACEHOLDER;

                var fileName = FileUtils.GetTempFileName("placeholders\\" + group + "_placeholder.png");
                if (File.Exists(fileName))
                {
                    _bitmapImage.UriSource = FileUtils.GetTempFileUri("placeholders//" + group + "_placeholder.png");
                }
                else
                {
                    var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(SettingsHelper.SessionGuid + "\\temp\\placeholders\\" + group + "_placeholder.png", CreationCollisionOption.OpenIfExists);

                    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        if (stream.Size == 0)
                        {
                            PlaceholderImageSource.Draw(BindConvert.Current.Bubble(id).Color, InitialNameStringConverter.Convert(value), stream);
                            stream.Seek(0);
                        }

                        _bitmapImage.SetSource(stream);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static ImageSource GetBadge(string text, Color color, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(color, InitialNameStringConverter.Convert(text), stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }