コード例 #1
0
ファイル: SvgPage.xaml.cs プロジェクト: netcharm/StringCodec
        private async void MakeImages(List <Size> sizelist)
        {
            var wb = await imgSvg.ToWriteableBitmap();

            var valid = true;

            if (!(wb is WriteableBitmap))
            {
                wb    = new WriteableBitmap(1, 1);
                valid = false;
            }

            if (wb is WriteableBitmap)
            {
                var w      = (int)imgSvg.ActualWidth;
                var h      = (int)imgSvg.ActualHeight;
                var factor = (double)h / (double)w;

                double l = 0;
                double t = 0;
                double r = 0;
                double b = 0;
                if (w < h)
                {
                    l = r = (h - w) / 2.0;
                }
                else
                {
                    t = b = (w - h) / 2.0;
                }
                wb = wb.Extend((int)l, (int)t, (int)r, (int)b, Colors.Transparent);

                imagelist.Clear();
                foreach (var s in sizelist)
                {
                    try
                    {
                        var tw   = s.Width;
                        var th   = s.Height;
                        var item = new ImageItem()
                        {
                            IsValid   = valid,
                            Size      = (int)Math.Max(s.Width, s.Height),
                            Text      = $"{tw}x{th}",
                            Margin    = new Thickness(-12, 0, 0, 0),
                            MinHeight = 96,
                            MaxHeight = 256,
                            Width     = 256,
                            Source    = wb.Resize((int)tw, (int)th, WriteableBitmapExtensions.Interpolation.Bilinear)
                        };
                        if (imgSvg.Tag is byte[])
                        {
                            item.Bytes = imgSvg.Tag as byte[];
                        }
                        if (tw > MinHeight)
                        {
                            item.Height = tw;
                        }
                        if (!string.IsNullOrEmpty(SourceFileName))
                        {
                            item.SourceName = SourceFileName;
                        }
                        imagelist.Add(item);
                    }
                    catch (Exception ex)
                    {
                        await new MessageDialog(ex.Message.T(), "ERROR".T()).ShowAsync();
                    }
                }
            }
        }
コード例 #2
0
ファイル: SvgPage.xaml.cs プロジェクト: netcharm/StringCodec
        private async void MakeImages(List <int> sizelist)
        {
            var wb = await imgSvg.ToWriteableBitmap();

            var valid = true;

            if (!(wb is WriteableBitmap))
            {
                wb    = new WriteableBitmap(1, 1);
                valid = false;
            }

            if (wb is WriteableBitmap)
            {
                var w      = (int)imgSvg.ActualWidth;
                var h      = (int)imgSvg.ActualHeight;
                var factor = (double)h / (double)w;
                if (CURRENT_SQUARE)
                {
                    if (w < h)
                    {
                        var delta = (int)((h - w) / 2);
                        wb = wb.Extend(delta, 0, delta, 0, Colors.Transparent);
                    }
                    else if (w > h)
                    {
                        var delta = (int)((w - h) / 2);
                        wb = wb.Extend(0, delta, 0, delta, Colors.Transparent);
                    }
                    factor = 1;
                }

                //ImageList.ItemsSource = null;
                //List<int> sizelist = new List<int>() { 256, 128, 96, 72, 64, 48, 32, 24, 16 };
                imagelist.Clear();
                foreach (var s in sizelist)
                {
                    try
                    {
                        var item = new ImageItem()
                        {
                            IsValid   = valid,
                            Size      = s,
                            Text      = $"{s}x{s}",
                            Margin    = new Thickness(-12, 0, 0, 0),
                            MinHeight = 96,
                            MaxHeight = 256,
                            Width     = 256,
                            Source    = wb.Resize((int)s, (int)(s * factor), WriteableBitmapExtensions.Interpolation.Bilinear)
                        };
                        if (imgSvg.Tag is byte[])
                        {
                            item.Bytes = imgSvg.Tag as byte[];
                        }
                        if (s > MinHeight)
                        {
                            item.Height = s;
                        }
                        if (!string.IsNullOrEmpty(SourceFileName))
                        {
                            item.SourceName = SourceFileName;
                        }
                        imagelist.Add(item);
                    }
                    catch (Exception ex)
                    {
                        await new MessageDialog(ex.Message.T(), "ERROR".T()).ShowAsync();
                    }
                }
                //ImageList.ItemsSource = imagelist;
                //ImageList.SelectionMode = ListViewSelectionMode.None;
            }
        }