Esempio n. 1
0
        public void GenerateRasterImage()
        {
            if (!string.IsNullOrEmpty(originalFile))
            {
                try
                {
                    nQuant.WuQuantizer    quantizer = new nQuant.WuQuantizer();
                    System.Drawing.Bitmap bitmap    = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(originalFile);

                    quantizer.QuantizeImage(bitmap);
                    rectangle1.Background = new SolidColorBrush(Color.FromRgb(quantizer.Palette.Colors[0].R, quantizer.Palette.Colors[0].G, quantizer.Palette.Colors[0].B));
                    rectangle2.Background = new SolidColorBrush(Color.FromRgb(quantizer.Palette.Colors[1].R, quantizer.Palette.Colors[1].G, quantizer.Palette.Colors[1].B));
                    rectangle3.Background = new SolidColorBrush(Color.FromRgb(quantizer.Palette.Colors[2].R, quantizer.Palette.Colors[2].G, quantizer.Palette.Colors[2].B));
                    rectangle4.Background = new SolidColorBrush(Color.FromRgb(quantizer.Palette.Colors[3].R, quantizer.Palette.Colors[3].G, quantizer.Palette.Colors[3].B));

                    QuantizedSignedDistanceFieldGenerator generator = new QuantizedSignedDistanceFieldGenerator(quantizer.Palette, bitmap.Height, bitmap.Width);
                    generator.Generate(0);
                    generator.Generate(1);
                    generator.Generate(2);
                    generator.Generate(3);

                    quantizedBitmap = generator.GetBitmap();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error during generation", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Esempio n. 2
0
        public void GenerateRasterImage(string originalFile)
        {
            if (!string.IsNullOrEmpty(originalFile))
            {
                try
                {
                    nQuant.WuQuantizer    quantizer = new nQuant.WuQuantizer();
                    System.Drawing.Bitmap bitmap    = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(originalFile);

                    quantizer.QuantizeImage(bitmap);

                    QuantizedSignedDistanceFieldGenerator generator = new QuantizedSignedDistanceFieldGenerator(quantizer.Palette, bitmap.Height, bitmap.Width);
                    generator.Generate(0);
                    generator.Generate(1);
                    generator.Generate(2);
                    generator.Generate(3);

                    RasterImage RasterResult = RasterImage.CreateFromBitmap(generator.GetBitmap());

                    uint InstanceId = TGIRandomGenerator.GetNext();

                    DatabaseIndex newIndex = new DatabaseIndex(OriginalIndex.Owner);
                    newIndex.TypeId       = (uint)TypeIds.RasterFile;
                    newIndex.InstanceId   = InstanceId;
                    newIndex.Flags        = 1;
                    newIndex.IsModified   = true;
                    newIndex.Compressed   = false;
                    newIndex.ModifiedData = new ModifiedRasterFile()
                    {
                        ImageFileData = RasterResult.ToIndexData()
                    };
                    OriginalIndex.Owner.Indices.Add(newIndex);
                    SimCityPak.PackageReader.DatabaseManager.Instance.Indices.Add(newIndex);

                    UnitFileEntry.LotMask.InstanceId = InstanceId;
                    //quantizer.Palette.Colors[0].Scr
                    Color col = Color.FromArgb(quantizer.Palette.Colors[0].A, quantizer.Palette.Colors[0].R, quantizer.Palette.Colors[0].G, quantizer.Palette.Colors[0].B);
                    UnitFileEntry.LotColor4.R = col.ScR;
                    UnitFileEntry.LotColor4.G = col.ScG;
                    UnitFileEntry.LotColor4.B = col.ScB;

                    col = Color.FromArgb(quantizer.Palette.Colors[1].A, quantizer.Palette.Colors[1].R, quantizer.Palette.Colors[1].G, quantizer.Palette.Colors[1].B);
                    UnitFileEntry.LotColor1.R = col.ScR;
                    UnitFileEntry.LotColor1.G = col.ScG;
                    UnitFileEntry.LotColor1.B = col.ScB;

                    col = Color.FromArgb(quantizer.Palette.Colors[2].A, quantizer.Palette.Colors[2].R, quantizer.Palette.Colors[2].G, quantizer.Palette.Colors[2].B);
                    UnitFileEntry.LotColor2.R = col.ScR;
                    UnitFileEntry.LotColor2.G = col.ScG;
                    UnitFileEntry.LotColor2.B = col.ScB;

                    col = Color.FromArgb(quantizer.Palette.Colors[3].A, quantizer.Palette.Colors[3].R, quantizer.Palette.Colors[3].G, quantizer.Palette.Colors[3].B);
                    UnitFileEntry.LotColor3.R = col.ScR;
                    UnitFileEntry.LotColor3.G = col.ScG;
                    UnitFileEntry.LotColor3.B = col.ScB;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error during generation", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }