Example #1
0
        public void TestAddAndRemove()
        {
            Palette palette = new Palette();

            Assert.AreEqual(0, palette.Count);

            palette.Add(new Color(1));
            Assert.AreEqual(1, palette.Count);

            palette.Add(new Color(255));
            Assert.AreEqual(2, palette.Count);

            palette.Add(new Color(1));
            Assert.AreEqual(2, palette.Count);

            AssertColorInPalette(palette, 1, 1);
            AssertColorInPalette(palette, 255, 255);

            palette.Remove(100);
            Assert.AreEqual(2, palette.Count, "No error on removing non-existing color");

            palette.Remove(1);
            Assert.AreEqual(1, palette.Count);

            AssertColorInPalette(palette, 255, 255);

            palette.Clear();
            Assert.AreEqual(0, palette.Count);
        }
Example #2
0
        public void AddTest()
        {
            ReportStart();
            _actual = new Palette();

            // Add a first colour and check it's the only one in the palette
            _actual.Add(Color.AliceBlue);
            Assert.AreEqual(1, _actual.Count);
            ColourAssert.AreEqual(Color.AliceBlue, _actual[0]);

            // Add a second colour and check both are in the palette
            _actual.Add(Color.AntiqueWhite);
            Assert.AreEqual(2, _actual.Count);
            ColourAssert.AreEqual(Color.AliceBlue, _actual[0]);
            ColourAssert.AreEqual(Color.AntiqueWhite, _actual[1]);

            // Add a colour that's already in the palette, and check nothing has changed
            _actual.Add(Color.AliceBlue);
            Assert.AreEqual(2, _actual.Count);
            ColourAssert.AreEqual(Color.AliceBlue, _actual[0]);
            ColourAssert.AreEqual(Color.AntiqueWhite, _actual[1]);

            // Add a third colour and check that all 3 are in the palete
            _actual.Add(Color.Aqua);
            Assert.AreEqual(3, _actual.Count);
            ColourAssert.AreEqual(Color.AliceBlue, _actual[0]);
            ColourAssert.AreEqual(Color.AntiqueWhite, _actual[1]);
            ColourAssert.AreEqual(Color.Aqua, _actual[2]);
            ReportEnd();
        }
Example #3
0
        public void TestIndexer()
        {
            var palette = new Palette();

            palette.Add(new Color(1));
            palette.Add(new Color(2));

            Assert.AreEqual(new Color(1), palette[1]);
            Assert.AreEqual(new Color(2), palette[2]);
            Assert.IsNull(palette[3]);
        }
Example #4
0
        public void FromFileTest()
        {
            ReportStart();
            foreach (string file in _paletteFiles)
            {
                _actual = Palette.FromFile(file);

                _expected = new Palette();
                byte[] bytes = File.ReadAllBytes(file);
                for (int i = 0; i < bytes.Length; i += 3)
                {
                    Color c = Color.FromArgb(bytes[i], bytes[i + 1], bytes[i + 2]);
                    _expected.Add(c);
                }

                Assert.AreEqual(_expected.Count, _actual.Count, file);

                for (int i = 0; i < _expected.Count; i++)
                {
                    ColourAssert.AreEqual(_expected[i], _actual[i],
                                          file + " Colour number " + i);
                }
            }
            ReportEnd();
        }
Example #5
0
        public void CalculatePalette(int colorCount = 256)
        {
            if (colorCount > 256)
            {
                colorCount = 256;                   // For some reason it fails with more...
            }
            var colorThief = new ColorThief();

            var palette = new List <QuantizedColor>();

            using (var image = ToBitmap())
                palette = colorThief.GetPalette(image, colorCount, 10, false);

            // Sort colours by YIQ luma so they align nicely
            var sortedPalette = palette.OrderBy(entry => entry.CalculateYiqLuma(entry.Color));

            Palette.Clear();
            foreach (var color in sortedPalette)
            {
                if (color.Color.ToHsl().L > 0.009) // Filter out dark values
                {
                    var newColor = new ColorC(color.Color.R, color.Color.G, color.Color.B);
                    if (!Palette.Contains(newColor)) // Filter out duplicates
                    {
                        Palette.Add(newColor);
                    }
                }
            }
        }
		IndexedBitmap CreateImage()
		{
			var image = new IndexedBitmap(100, 100, 8, Generator);
			var ega = Palette.GetEgaPalette();
			var pal = new Palette(ega);
			
			// must have at least 256 colors for an 8-bit bitmap
			while (pal.Count < 256)
				pal.Add(Colors.Black);
			image.Palette = pal;
			using (var bd = image.Lock())
			{
				unsafe
				{
					var brow = (byte*)bd.Data;
					for (int y = 0; y < image.Size.Height; y++)
					{
						byte* b = brow;
						var col = -y;
						for (int x = 0; x < image.Size.Width; x++)
						{
							while (col < 0)
								col = ega.Count + col;
							while (col >= ega.Count)
								col -= ega.Count;
							*b = (byte)col++;
							b++;
						}
						brow += bd.ScanWidth;
					}
				}
			}
			return image;
			
		}
Example #7
0
		IndexedBitmap CreateImage()
		{
			var image = new IndexedBitmap (100, 100, 8);
			var pal = new Palette (Palette.GetEgaPalette ());
			
			// must have at least 256 colors for an 8-bit bitmap
			while (pal.Count < 256)
				pal.Add (Color.Black);
			image.Palette = pal;
			var bd = image.Lock ();
			
			unsafe {
				int col = 0;
				byte* brow = (byte*)bd.Data;
				for (int y = 0; y < image.Size.Height; y++) {
					byte* b = brow;
					for (int x = 0; x < image.Size.Width; x++) {
						if (col >= pal.Count) 
							col = 0;
						*b = (byte)col++;
						b++;
					}
					brow += bd.ScanWidth;
				}
			}
			image.Unlock (bd);
			return image;
			
		}
Example #8
0
        // Creates a range colorizer.
        ChartColorizerBase CreateColorizer()
        {
            Palette palette = new Palette("Custom");

            palette.Add(Color.FromArgb(255, 255, 90, 25), Color.FromArgb(255, 255, 90, 25));
            palette.Add(Color.FromArgb(255, 229, 227, 53), Color.FromArgb(255, 229, 227, 53));
            palette.Add(Color.FromArgb(255, 110, 201, 92), Color.FromArgb(255, 110, 201, 92));

            RangeColorizer colorizer = new RangeColorizer()
            {
                LegendItemPattern = "{V1} - {V2} HPI",
                Palette           = palette
            };

            colorizer.RangeStops.AddRange(new double[] { 22, 30, 38, 46, 54, 64 });
            return(colorizer);
        }
Example #9
0
        public void AddTest()
        {
            Palette palette = new Palette();
            Assert.AreEqual(0, palette.Count);

            palette.Add(0, Colors.Red);
            Assert.AreEqual(1, palette.Count);
            Assert.AreEqual(new PaletteEntry(0, Colors.Red), palette[0]);

            palette.Add(2, Colors.Blue);
            Assert.AreEqual(2, palette.Count);
            Assert.AreEqual(new PaletteEntry(2, Colors.Blue), palette[1]);

            palette.Add(new PaletteEntry(1, Colors.Green));
            Assert.AreEqual(3, palette.Count);
            Assert.AreEqual(new PaletteEntry(1, Colors.Green), palette[2]);
        }
Example #10
0
        public void TestAddRemoveEvents()
        {
            int   addedCount            = 0;
            int   removedCount          = 0;
            Color lastAddedRemovedColor = null;

            var palette = new Palette();

            palette.ColorAdded +=
                (sender, e) =>
            {
                addedCount++;
                lastAddedRemovedColor = e.Color;
                Assert.AreSame(palette, sender);
            };
            palette.ColorRemoved +=
                (sender, e) =>
            {
                removedCount++;
                lastAddedRemovedColor = e.Color;
                Assert.AreSame(palette, sender);
            };

            Action <int, int, Color> doAsserts =
                (expectAdded, expectRemoved, expectColor) =>
            {
                Assert.AreEqual(expectAdded, addedCount);
                Assert.AreEqual(expectRemoved, removedCount);
                Assert.AreEqual(expectColor, lastAddedRemovedColor);
            };

            palette.Add(new Color(1));
            doAsserts(1, 0, new Color(1));

            palette.Add(new Color(2));
            doAsserts(2, 0, new Color(2));

            palette.Add(new Color(1));
            doAsserts(2, 0, new Color(2));

            palette.Remove(1);
            doAsserts(2, 1, new Color(1));

            palette.Remove(3);
            doAsserts(2, 1, new Color(1));
        }
Example #11
0
        public void AddTest()
        {
            Palette palette = new Palette();
            Assert.AreEqual(0, palette.Count);

            palette.Add(0, Colors.Red);
            Assert.AreEqual(1, palette.Count);
            Assert.AreEqual(new PaletteEntry(0, Colors.Red), palette[0]);

            palette.Add(2, Colors.Blue);
            Assert.AreEqual(2, palette.Count);
            Assert.AreEqual(new PaletteEntry(2, Colors.Blue), palette[1]);

            palette.Add(new PaletteEntry(1, Colors.Green));
            Assert.AreEqual(3, palette.Count);
            Assert.AreEqual(new PaletteEntry(1, Colors.Green), palette[2]);
        }
Example #12
0
        public static Palette ReadPalette(this NetIncomingMessage message)
        {
            var count   = message.ReadInt32();
            var palette = new Palette();

            for (int i = 0; i < count; i++)
            {
                palette.Add(message.ReadColor());
            }
            return(palette);
        }
Example #13
0
        public void TestAddCreatesNewInstance()
        {
            Color   color   = new Color(1, 2, 3, 4);
            Palette palette = new Palette();

            palette.Add(color);
            Color paletteColor = palette[color.GetHashCode()];

            Assert.IsNotNull(paletteColor);
            Assert.AreEqual(color, paletteColor);
            Assert.AreNotSame(color, paletteColor);
        }
Example #14
0
        public void ToStringTest()
        {
            ReportStart();
            _actual = new Palette();

            for (int i = 0; i < 256; i++)
            {
                Color c = Color.FromArgb(i, i, i);
                _actual.Add(c);
                Assert.AreEqual((i + 1) + " colours", _actual.ToString());
            }
            ReportEnd();
        }
Example #15
0
        /// <summary>
        /// Carregars the paleta cores relaorio.
        /// </summary>
        /// <param name="lstCoresRelatorio">Lista de cores que serão carregadas na paleta</param>
        /// <returns>Palette</returns>
        public static Palette CarregarPaletaCoresRelatorio(List <string> lstCoresRelatorio)
        {
            Palette PaletaCores = new Palette("Gestao", PaletteScaleMode.Repeat);

            List <PaletteEntry> ltPaletaCores = lstCoresRelatorio.Select(p => new PaletteEntry(ColorTranslator.FromHtml(p))).ToList();

            foreach (PaletteEntry Paleta in ltPaletaCores)
            {
                PaletaCores.Add(Paleta);
            }

            return(PaletaCores);
        }
Example #16
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            // If they are using the Colors parameter set, we're collecting all the colors as they come in
            if (Colors != null)
            {
                parameterName = "Colors";
                foreach (var color in Colors)
                {
                    colors.Add(color);
                }
            }
        }
Example #17
0
 public void AddTestMaxColours()
 {
     ReportStart();
     _actual = new Palette();
     for (int i = 0; i < 256; i++)
     {
         Color c = Color.FromArgb(i, i, i);
         _actual.Add(c);
         Assert.AreEqual(i + 1, _actual.Count);
     }
     try
     {
         _actual.Add(Color.FromArgb(1, 2, 3));
     }
     catch (InvalidOperationException ex)
     {
         string message
             = "This palette already contains the maximum number of "
               + "colours allowed.";
         StringAssert.Contains(message, ex.Message);
         ReportEnd();
         throw;
     }
 }
Example #18
0
        public static Palette CarregarPaletaCoresRelaorio(int rlt_id)
        {
            List <string> lstCoresRelatorio = CFG_CorRelatorioBO.SelecionaCoresRelatorio(rlt_id).Select(p => p.cor_corPaleta).ToList();

            Palette PaletaCores = new Palette("Gestao", PaletteScaleMode.Repeat);

            List <PaletteEntry> ltPaletaCores = lstCoresRelatorio.Select(p => new PaletteEntry(ColorTranslator.FromHtml(p))).ToList();

            foreach (PaletteEntry Paleta in ltPaletaCores)
            {
                PaletaCores.Add(Paleta);
            }

            return(PaletaCores);
        }
Example #19
0
        public GraphicsEditor()
        {
            InitializeComponent();

            Tileset_2bpp_RadioButton.Enabled = false;

            GrayScale = new Palette();
            byte value;

            for (int i = 0; i < Palette.MAX; i++)
            {
                value = (byte)(i * 16);
                GrayScale.Add(new GBA.Color(0, value, value, value));
            }
        }
Example #20
0
        /// <summary>
        /// Loads in the palette of all KnownColors, excluding Transparent and the SystemColors.
        /// </summary>
        private void LoadKnownColorsPalette()
        {
            _baseList.Clear();

            // Get the list of all the colors in the System.Drawing.KnowColor enum, including the system colors.
            var AllColors = new List <string>();

            AllColors.AddRange(Enum.GetNames(typeof(System.Drawing.KnownColor)));

            var SystemEnvironmentColors = GetSystemColorNames();

            SystemEnvironmentColors.Add("Transparent");
            foreach (var ColorName in AllColors)
            {
                if (!SystemEnvironmentColors.Contains(ColorName))
                {
                    _baseList.Add(new NamedColor(ColorName, Color.FromName(ColorName)));
                }
            }
            AllColors = null;
            SystemEnvironmentColors = null;

            this.Refresh();
        }
Example #21
0
        /// <summary>
        /// Replaces all colors in palette on its substitutes from destination palette.
        /// </summary>
        /// <param name="palette">Source palette with colors which should be substituted.</param>
        /// <param name="destPalette">Palette with destination colors.</param>
        public static void SubstColorsFromPalette(this Palette palette, Palette destPalette)
        {
            Debug.Assert(destPalette.Count >= palette.Count, "Too few colors in destination palette.");

            Color[] oldColors = palette.OrderByCount(true).ToArray();
            palette.Clear();

            PaletteQuickColorSearcher searcher = new PaletteQuickColorSearcher(destPalette);

            foreach (Color oldColor in oldColors)
            {
                Color substituteColor = searcher.SearchSubstitute(oldColor, true);
                Debug.Assert(substituteColor != null, "Substitute color was not found.");
                palette.Add(substituteColor);
            }
        }
Example #22
0
        public void Test()
        {
            Endogine.ColorEx.Palette pal = new Palette();
            ColorHsb hsb = new ColorHsb();

            hsb.A = 255;
            hsb.S = 0.5f;
            Point p = new Point(15, 15);

            for (int i = 0; i < p.X; i++)
            {
                hsb.B = 1f - (float)i / p.X;
                for (int j = 0; j < p.Y; j++)
                {
                    hsb.H = 359f * (float)j / p.Y;
                    pal.Add("Red", new ColorRgb(hsb.ColorRGBA));
                }
            }
            this.Palette = pal;
        }
Example #23
0
        Control AddButton()
        {
            var control = new CustomButton {
                Size = new Size(17, 17)
            };

            control.Paint += delegate(object sender, PaintEventArgs pe)
            {
                var size = pe.Graphics.MeasureString(font, "+");
                pe.Graphics.DrawText(font, control.DrawColor, (int)(control.Size.Width - size.Width) / 2, (int)(control.Size.Height - size.Height - 1) / 2, "+");
            };

            control.Click += delegate
            {
                Palette.Add(Colors.White);
                SelectedIndex = Palette.Count - 1;
                UpdateColours();
            };
            return(control);
        }
Example #24
0
        IndexedBitmap CreateImage()
        {
            var image = new IndexedBitmap(100, 100, 8);
            var ega   = Palette.GetEgaPalette();
            var pal   = new Palette(ega);

            // must have at least 256 colors for an 8-bit bitmap
            while (pal.Count < 256)
            {
                pal.Add(Colors.Black);
            }
            image.Palette = pal;
            using (var bd = image.Lock())
            {
                unsafe
                {
                    int   col  = 0;
                    byte *brow = (byte *)bd.Data;
                    for (int y = 0; y < image.Size.Height; y++)
                    {
                        byte *b = brow;
                        col = -y;
                        for (int x = 0; x < image.Size.Width; x++)
                        {
                            while (col < 0)
                            {
                                col = ega.Count + col;
                            }
                            while (col >= ega.Count)
                            {
                                col -= ega.Count;
                            }
                            *b = (byte)col++;
                            b++;
                        }
                        brow += bd.ScanWidth;
                    }
                }
            }
            return(image);
        }
Example #25
0
        /// <summary>
        /// Create an Eto Palette from a packed, unsigned, 8-bit RGB byte array.
        /// </summary>
        /// <param name="destination">The Eto Palette to add colors to.</param>
        /// <param name="source">The stream containing the raw color values.</param>
        /// <returns></returns>
        public static Palette LoadQuakePalette(this Palette destination, Stream source)
        {
            var br = new BinaryReader(source);

            var length = source.Length;

            for (var i = 0; i < length / 3; i++)
            {
                var color = new Color()
                {
                    Ab = 255
                };
                color.Rb = br.ReadByte();
                color.Gb = br.ReadByte();
                color.Bb = br.ReadByte();

                destination.Add(color);
            }

            return(destination);
        }
Example #26
0
 private void FixEmptyValues()
 {
     if (string.IsNullOrEmpty(ProjectName))
     {
         ProjectName = "";
     }
     if (string.IsNullOrEmpty(Description))
     {
         Description = "";
     }
     if (FrontCover is null)
     {
         FrontCover = new ImageData();
     }
     if (Palette.Count == 0)
     {
         Palette.Add(Color.white);
     }
     if (Tweens.Count == 0)
     {
         Tweens.Add(AnimationCurve.Linear(0f, 0f, 1f, 1f));
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="colorCount"></param>
        /// <returns></returns>
        public override List <Color> GetPalette(Int32 colorCount)
        {
            cubeList.Clear();
            cubeList.Add(new MedianCutCube(colorList));

            if (colorList.Count == 0)//Returns empty if it has nothing to sort through.
            {
                return(Palette);
            }
            Palette.Clear();

            // finds the minimum iterations needed to achieve the cube count (color count) we need
            Int32 iterationCount = 1;

            while ((1 << iterationCount) < colorCount)
            {
                iterationCount++;
            }

            for (Int32 iteration = 0; iteration < iterationCount; iteration++)
            {
                SplitCubes(colorCount);
            }

            // initializes the result palette
            Int32 paletteIndex = 0;

            // adds all the cubes' colors to the palette, and mark that cube with palette index for later use
            foreach (MedianCutCube cube in cubeList)
            {
                Palette.Add(cube.AverageColor);
                cube.PaletteIndex = paletteIndex++;
            }
            // returns the palette (should contain <= ColorCount colors)
            return(Palette);
        }
Example #28
0
        /// <summary>
        /// Opens a Adobe Color Swatch file, and reads its content.
        /// </summary>
        private async void Open_Executed()
        {
            var openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
            openPicker.FileTypeFilter.Add(".aco");
            StorageFile file = await openPicker.PickSingleFileAsync();

            if (null != file)
            {
                try
                {
                    // User picked a file.
                    var stream = await file.OpenStreamForReadAsync();

                    var reader       = new AcoConverter();
                    var swatchColors = reader.ReadPhotoShopSwatchFile(stream);
                    Palette.Clear();
                    foreach (var color in swatchColors)
                    {
                        var pc = new NamedColor(color.Red, color.Green, color.Blue, color.Name);
                        Palette.Add(pc);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message);
                    Toast.ShowError("Oops, something went wrong.");
                }
            }
            else
            {
                // User cancelled.
                Toast.ShowWarning("Operation cancelled.");
            }
        }
Example #29
0
        public void ValidateTest()
        {
            ReportStart();
            // Check that each of the sample palettes pass validation
            foreach (string paletteFile in _paletteFiles)
            {
                try
                {
                    Palette p = Palette.FromFile(paletteFile);
                    p.Validate();
                }
                catch (InvalidOperationException ioe)
                {
                    string message
                        = "Sample palette fails validation: "
                          + paletteFile;
                    throw new AssertionExtensionException(message, ioe);
                }
            }

            // Try a palette which doesn't pass validation
            _actual = new Palette();
            _actual.Add(Color.FromArgb(1, 1, 1));
            try
            {
                _actual.Validate();
            }
            catch (InvalidOperationException ex)
            {
                string message
                    = "A palette with less than two colours is not valid.";
                StringAssert.Contains(message, ex.Message);
                ReportEnd();
                throw;
            }
        }
Example #30
0
 public void Test()
 {
     Endogine.ColorEx.Palette pal = new Palette();
     ColorHsb hsb = new ColorHsb();
     hsb.A = 255;
     hsb.S = 0.5f;
     Point p = new Point(15, 15);
     for (int i = 0; i < p.X; i++)
     {
         hsb.B = 1f - (float)i / p.X;
         for (int j = 0; j < p.Y; j++)
         {
             hsb.H = 359f * (float)j / p.Y;
             pal.Add("Red", new ColorRgb(hsb.ColorRGBA));
         }
     }
     this.Palette = pal;
 }
Example #31
0
        public static Palette GetDefaultPalette()
        {
            var swatches = new Swatches(); 
            var pal = new Palette();
            pal.Add(swatches.FadedDarkBlue);
            pal.Add(swatches.BrightOrange);
            pal.Add(swatches.SimpleGreen);
            pal.Add(swatches.PurpleByzantium);
            pal.Add(swatches.Jonquil);
            pal.Add(swatches.FireEngineRed);
            pal.Add(swatches.LightGray);
            pal.Add(swatches.DeepBlue);
            pal.Add(swatches.DarkGray);
            pal.Add(swatches.ForestGreen);
            pal.Add(swatches.Carmine);
            pal.Add(swatches.BrightPink);
            pal.Add(swatches.Eggplant);
            pal.Add(swatches.Byzantine);
            pal.Add(swatches.JungleGreen);
            pal.Add(swatches.Black);
            pal.Add(swatches.Jonquil);
            pal.Add(swatches.Chamoisee);

            return pal;
        }
Example #32
0
 public override void InitilizeLandRegion(Land land, LandRegionType land_region_type, Palette <LandRegionSplat> palette)
 {
     palette.Add(main_splat);
     palette.Add(secondary_splat);
 }
Example #33
0
        private void CreateStatisticTheme(string LayerName)
        {
            //创建组
            string GroupName = "统计专题_" + LayerName;
            int GroupID = Program.sgworld.ProjectTree.CreateGroup(GroupName);
            //根据获取的位置及表中的值建立

                if (StaThemePos != null)
                {
                    this.progressBarControl1.Properties.Minimum = 0;
                    this.progressBarControl1.Properties.Maximum = StaThemePos.Count;
                    this.progressBarControl1.Properties.Step = 1;
                    this.progressBarControl1.Position = 0;

                    for (int i = 0; i < StaThemePos.Count; i++)
                    {
                        //根据图表类型获取字段值根据设置生成图像
                        #region
                        ChartControl Chart3D = new ChartControl();
                        ChartTitle chartTitle1 = new ChartTitle();
                        Chart3D.Titles.Add(chartTitle1);
                        string AValue = "";
                        switch (this.comboBoxChartType.Text)
                        {
                            case "柱状图":
                                //每个字段对应一个Series,字段名以及该要素该字段的值构成一个Point
                                foreach (DataGridViewRow ARow in this.dataGridView3.Rows)
                                {
                                    Series Aseries = new Series("Aseries", ViewType.Bar3D);
                                    AValue = this.dataGridView4.Rows[i].Cells[ARow.Cells[1].Value.ToString()].Value.ToString();
                                    Aseries.Points.Add(new SeriesPoint(ARow.Cells[1].Value.ToString(), Convert.ToDouble(AValue)));
                                    Chart3D.Series.Add(Aseries);

                                    ((BarSeriesLabel)Aseries.Label).Visible = true;
                                    Font myFont = new Font(new FontFamily("宋体"),20);
                                    ((BarSeriesLabel)Aseries.Label).Font = myFont;
                                    ((BarSeriesLabel)Aseries.Label).BackColor = Color.FromArgb(0, 0, 0, 0);
                                    ((BarSeriesLabel)Aseries.Label).Border.Visible = false;
                                    ((BarSeriesLabel)Aseries.Label).TextColor = Color.Black;
                                    ((BarSeriesLabel)Aseries.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default;
                                    Aseries.PointOptions.PointView = PointView.ArgumentAndValues;
                                    //是否勾选百分比
                                    //if (this.checkPercent.Checked)
                                    //    Aseries.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

                                    ((Bar3DSeriesView)Aseries.View).Model = Bar3DModel.Cylinder;
                                    //修改柱状体颜色
                                    ((Bar3DSeriesView)Aseries.View).Color = ARow.Cells[0].Style.BackColor;

                                    ((XYDiagram3D)Chart3D.Diagram).AxisX.GridLines.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisX.Label.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisY.GridLines.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisY.Label.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisY.Interlaced = false;
                                    ((XYDiagram3D)Chart3D.Diagram).BackColor = Color.FromArgb(0, 0, 0, 0);
                                }
                                break;
                            case "堆叠柱状图":
                                //每个字段对应一个Series,每个Series一个Point,Argument值相同,Value值对应各字段值,起码2个Series才有堆叠效果
                                foreach (DataGridViewRow ARow in this.dataGridView3.Rows)
                                {
                                    Series Aseries = new Series("Aseries", ViewType.StackedBar3D);
                                    AValue = this.dataGridView4.Rows[i].Cells[ARow.Cells[1].Value.ToString()].Value.ToString();
                                    Aseries.Points.Add(new SeriesPoint(this.dataGridView4.Rows[i].Cells[0].Value.ToString(), Convert.ToDouble(AValue)));
                                    Chart3D.Series.Add(Aseries);

                                    ((BarSeriesLabel)Aseries.Label).Visible = true;
                                    Font myFont = new Font(new FontFamily("宋体"), 20);
                                    ((BarSeriesLabel)Aseries.Label).Font = myFont;
                                    ((BarSeriesLabel)Aseries.Label).BackColor = Color.FromArgb(0, 0, 0, 0);
                                    ((BarSeriesLabel)Aseries.Label).Border.Visible = false;
                                    ((BarSeriesLabel)Aseries.Label).TextColor = Color.Black;
                                    ((BarSeriesLabel)Aseries.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default;
                                    Aseries.PointOptions.PointView = PointView.ArgumentAndValues;
                                    //是否勾选百分比
                                    //if (this.checkPercent.Checked)
                                    //    Aseries.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;

                                    ((Bar3DSeriesView)Aseries.View).Model = Bar3DModel.Cylinder;
                                    //修改柱状体颜色
                                    ((Bar3DSeriesView)Aseries.View).Color = ARow.Cells[0].Style.BackColor;

                                    ((XYDiagram3D)Chart3D.Diagram).AxisX.GridLines.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisX.Label.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisY.GridLines.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisY.Label.Visible = false;
                                    ((XYDiagram3D)Chart3D.Diagram).AxisY.Interlaced = false;
                                    ((XYDiagram3D)Chart3D.Diagram).BackColor = Color.FromArgb(0, 0, 0, 0);
                                }
                                break;
                            case "饼图":
                                //每个要素仅含一个Series,每个字段对应一个Point,分别由字段名和字段值组成
                                Series Aseries1 = new Series("Aseries1", ViewType.Pie3D);
                                Palette Colorlist = new Palette("Colorlist");
                                foreach (DataGridViewRow ARow in this.dataGridView3.Rows)
                                {
                                    AValue = this.dataGridView4.Rows[i].Cells[ARow.Cells[1].Value.ToString()].Value.ToString();
                                    Aseries1.Points.Add(new SeriesPoint(ARow.Cells[1].Value.ToString(), Convert.ToDouble(AValue)));
                                    //Aseries1.Points.Add(new SeriesPoint(ARow.Cells[1].Value.ToString(), 50));
                                    Colorlist.Add(ARow.Cells[0].Style.BackColor);
                                }
                                Chart3D.Series.Add(Aseries1);
                                //修改饼颜色
                                Chart3D.PaletteRepository.Add("Colorlist", Colorlist);
                                Chart3D.PaletteName = "Colorlist";
                                Chart3D.PaletteBaseColorNumber = 0;

                                ((Pie3DSeriesLabel)Aseries1.Label).Visible = true;
                                 Font myFont1 = new Font(new FontFamily("宋体"),10);
                                ((Pie3DSeriesLabel)Aseries1.Label).Font = myFont1;
                                ((Pie3DSeriesLabel)Aseries1.Label).BackColor = Color.FromArgb(0, 0, 0, 0);
                                ((Pie3DSeriesLabel)Aseries1.Label).Border.Visible = false;
                                ((Pie3DSeriesLabel)Aseries1.Label).TextColor = Color.Black;
                                ((Pie3DSeriesLabel)Aseries1.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default;
                                Aseries1.PointOptions.PointView = PointView.ArgumentAndValues;

                                //是否勾选百分比
                                if (this.checkPercent.Checked)
                                {
                                    Aseries1.PointOptions.ValueNumericOptions.Format = DevExpress.XtraCharts.NumericFormat.Percent;
                                    Aseries1.PointOptions.ValueNumericOptions.Precision = 1;
                                }

                                break;
                            default:
                                break;
                        }
                        chartTitle1.Text = this.dataGridView4.Rows[i].Cells[0].Value.ToString();
                        chartTitle1.TextColor = Color.White;
                        chartTitle1.WordWrap = true;
                        Chart3D.BackColor = Color.FromArgb(0, 0, 0, 0);
                        Chart3D.BorderOptions.Visible = false;
                        Chart3D.Size =new Size(400,400);
                        Chart3D.Legend.Visible = false;

                        Chart3D.ExportToImage(Application.StartupPath + "temp_" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);

                        //使图片透明
                        Bitmap oldbmp = new Bitmap(Application.StartupPath + "temp_" + i + ".png");
                        Bitmap newbmp = new Bitmap(oldbmp.Width, oldbmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        newbmp.MakeTransparent();
                        for (int x = 0; x != oldbmp.Width; x++)
                        {
                            for (int y = 0; y != oldbmp.Height; y++)
                            {
                                Color AColor = oldbmp.GetPixel(x, y);
                                if (!(AColor.A == 255 & AColor.R == 238 & AColor.G == 238 & AColor.B == 238))
                                {
                                    newbmp.SetPixel(x, y, Color.FromArgb(AColor.A, AColor.R, AColor.G, AColor.B));
                                }
                            }
                        }
                        newbmp.Save(Application.StartupPath + "temp2_" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
                        oldbmp.Dispose();
                        #endregion
                        //创建Label,后删除图片
                        ILabelStyle61 cLabelStyle = null;
                        ITerrainImageLabel61 cImageLabel = null;
                        //根据设置创建标签风格
                        SGLabelStyle eLabelStyle = SGLabelStyle.LS_DEFAULT;
                        cLabelStyle = Program.sgworld.Creator.CreateLabelStyle(eLabelStyle);
                        //随图缩放
                        cLabelStyle.LimitScreenSize = true;
                        //最大可视高度
                        cLabelStyle.MaxViewingHeight = 50000;
                        //最小可视高度
                        //cLabelStyle.MinViewingHeight = 10;
                        cLabelStyle.PivotAlignment = "Bottom,Left";
                        cImageLabel = Program.sgworld.Creator.CreateImageLabel(StaThemePos[i], Application.StartupPath + "temp2_" + i + ".png", cLabelStyle, GroupID, this.dataGridView4.Rows[i].Cells[0].Value.ToString());
                        File.Delete(Application.StartupPath + "temp_" + i + ".png");
                        File.Delete(Application.StartupPath + "temp2_" + i + ".png");
                        System.Windows.Forms.Application.DoEvents();
                        this.progressBarControl1.PerformStep();
                    }

                }
        }
Example #34
0
		public override object EditValue( ITypeDescriptorContext context, 
		                                  IServiceProvider provider, 
		                                  object value )
		{
			Palette original = (Palette) value;
			try
			{
				IWindowsFormsEditorService editorService 
					= (IWindowsFormsEditorService) 
					provider.GetService( typeof( IWindowsFormsEditorService ) );
				
				_paletteForm = new PaletteForm();
				
				if( value == null )
				{
					value = new Palette();
				}
				
				// Take a copy of the original Palette in case the user cancels
				// the PaletteForm
				Palette copy = new Palette();
				foreach( Color c in original )
				{
					copy.Add( c );
				}
				
				_paletteForm.Value = original;
				_paletteForm.EditorService = editorService;
				DialogResult result = editorService.ShowDialog( _paletteForm );
				if( result == DialogResult.OK )
				{
					return _paletteForm.Value;
				}
				else
				{
					return copy;
				}
			}
			catch( Exception ex )
			{
				ExceptionForm ef = new ExceptionForm( ex );
				ef.ShowDialog();
				return original;
			}
		}
Example #35
0
        public static Palette GetCGPalette()
        {
            var pal = new Palette();

            pal.Add(Color.FromArgb(0, 0, 0));
            pal.Add(Color.FromArgb(255, 255, 255));
            pal.Add(Color.FromArgb(189, 24, 33));
            pal.Add(Color.FromArgb(49, 231, 198));
            pal.Add(Color.FromArgb(181, 24, 231));
            pal.Add(Color.FromArgb(24, 214, 24));
            pal.Add(Color.FromArgb(33, 24, 173));
            pal.Add(Color.FromArgb(222, 247, 8));
            pal.Add(Color.FromArgb(189, 66, 0));
            pal.Add(Color.FromArgb(107, 49, 0));
            pal.Add(Color.FromArgb(255, 74, 82));
            pal.Add(Color.FromArgb(66, 66, 66));
            pal.Add(Color.FromArgb(115, 115, 115));
            pal.Add(Color.FromArgb(90, 255, 90));
            pal.Add(Color.FromArgb(90, 82, 255));
            pal.Add(Color.FromArgb(165, 165, 165));
            return(pal);
        }
Example #36
0
        private Palette GenerateOutputPalette(IndexedImage sourceImage)
        {
            int[] pixels = sourceImage.Pixels;

            int alphaDec     = 30 + ((Sample - 1) / 3);
            int lengthCount  = pixels.Length;
            int samplePixels = lengthCount / Sample;
            int delta        = samplePixels / CyclesCount;
            int alpha        = InitAlpha;
            int biasRadius   = initBiasRadius;

            int rad = biasRadius >> RadiusBiasShift;

            if (rad <= 1)
            {
                rad = 0;
            }

            int step;

            if (lengthCount < MaxPrime)
            {
                step = 1;
            }
            else if ((lengthCount % Prime1) != 0)
            {
                step = Prime1;
            }
            else if ((lengthCount % Prime2) != 0)
            {
                step = Prime2;
            }
            else if ((lengthCount % Prime3) != 0)
            {
                step = Prime3;
            }
            else
            {
                step = Prime4;
            }

            for (int i = 0, pos = 0; i < samplePixels; i++)
            {
                if ((i % delta) == 0)
                {
                    if (i != 0)
                    {
                        alpha      -= alpha / alphaDec;
                        biasRadius -= biasRadius / RadiusDec;
                    }

                    rad = biasRadius >> RadiusBiasShift;
                    if (rad <= 1)
                    {
                        rad = 0;
                    }
                    for (int radIndex = 0; radIndex < rad; radIndex++)
                    {
                        radPower[radIndex] = alpha * (((rad * rad - radIndex * radIndex) * RadBias) / (rad * rad));
                    }
                }

                int p     = pixels[pos];
                int red   = (p & ColorBytes.RedMask) >> ColorBytes.RedBias;
                int green = (p & ColorBytes.GreenMask) >> ColorBytes.GreenBias;
                int blue  = (p & ColorBytes.BlueMask) >> ColorBytes.BlueBias;

                int r = red << NetBiasShift;
                int g = green << NetBiasShift;
                int b = blue << NetBiasShift;

                int j = SpecialFind(r, g, b);
                j = (j < 0) ? ContestFind(r, g, b) : j;

                // Don't learn for specials
                if (j >= SpecialColorsCount)
                {
                    AlterSingle(alpha, j, r, g, b);
                    if (rad != 0)
                    {
                        AlterNeighbors(rad, j, r, g, b);                         // Alter neighbors
                    }
                }

                pos += step;
                while (pos >= lengthCount)
                {
                    pos -= lengthCount;
                }
            }

            Palette palette = sourceImage.Palette.Clone();

            palette.Clear();
            for (int j = 0; j < ColorsCount; j++)
            {
                int red = network[j, ColorBytes.RedIdx] >> NetBiasShift;
                if (red < 0)
                {
                    red = 0;
                }
                if (red > 255)
                {
                    red = 255;
                }

                int green = network[j, ColorBytes.GreenIdx] >> NetBiasShift;
                if (green < 0)
                {
                    green = 0;
                }
                if (green > 255)
                {
                    green = 255;
                }

                int blue = network[j, ColorBytes.BlueIdx] >> NetBiasShift;
                if (blue < 0)
                {
                    blue = 0;
                }
                if (blue > 255)
                {
                    blue = 255;
                }

                palette.Add(new Color((byte)red, (byte)green, (byte)blue));
            }

            return(palette);
        }
Example #37
0
 /// <summary>
 /// Adds a new NamedColor object to the custom color list.
 /// </summary>
 /// <param name="color">NamedColor object to add.</param>
 public void AddColor(NamedColor color)
 {
     _combinedList.Clear();
     _customList.Add(color);
     this.Refresh();
 }