private async void CreateNewIcon() {
            await Task.Delay(100);
            if (Car == null) return;

            ValuesStorage.Set(_key, NewIconLabel.Text);
            // TODO: Save style?

            var bmp = new RenderTargetBitmap(64, 64, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(NewIcon);

            try {
                bmp.SaveAsPng(Car.UpgradeIcon);
            } catch (IOException ex) {
                NonfatalError.Notify(AppStrings.UpgradeIcon_CannotChange, AppStrings.UpgradeIcon_CannotChange_Commentary, ex);
            } catch (Exception ex) {
                NonfatalError.Notify(AppStrings.UpgradeIcon_CannotChange, ex);
            }
        }
Пример #2
0
        private async Task CreateNewIcon() {
            var size = new Size(64, 64);
            Result.Measure(size);
            Result.Arrange(new Rect(size));
            Result.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

            await Task.Delay(100);
            if (Skin == null) return;

            // TODO: save style?
            var bmp = new RenderTargetBitmap(64, 64, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(Result);

            if (Model.Value != @"0" && Model.Value != Skin.SkinNumber &&
                    ShowMessage(string.Format(AppStrings.LiveryIcon_ChangeNumber_Message, Model.Value), AppStrings.LiveryIcon_ChangeNumber_Title,
                            MessageBoxButton.YesNo) == MessageBoxResult.Yes) {
                Skin.SkinNumber = Model.Value;
            }

            try {
                bmp.SaveAsPng(Skin.LiveryImage);
            } catch (IOException e) {
                NonfatalError.Notify(AppStrings.LiveryIcon_CannotChange, AppStrings.LiveryIcon_CannotChange_Commentary, e);
            } catch (Exception e) {
                NonfatalError.Notify(AppStrings.LiveryIcon_CannotChange, e);
            }
        }
Пример #3
0
            private void MakeCollage(IEnumerable<string> imageFilenames, string outputFilename) {
                var collage = new Grid();
                foreach (var filename in imageFilenames) {
                    collage.Children.Add(new Image {
                        Source = LoadBitmapImage(filename),
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment = VerticalAlignment.Center,
                    });
                }

                collage.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                collage.Arrange(new Rect(0d, 0d, collage.DesiredSize.Width, collage.DesiredSize.Height));

                var bitmap = new RenderTargetBitmap((int)collage.DesiredSize.Width, (int)collage.DesiredSize.Height,
                        96, 96, PixelFormats.Default);
                bitmap.Render(collage);

                bitmap.SaveAsPng(outputFilename);
            }