ToArgb() public method

public ToArgb ( ) : int
return int
Exemplo n.º 1
0
 public static byte[] GetBytes(Color color, ColorType type)
 {
     switch (type)
     {
         case ColorType.ARGB8888_32:
             return ByteConverter.GetBytes(color.ToArgb());
         case ColorType.XRGB8888_32:
             color = Color.FromArgb(0, color);
             goto case ColorType.ARGB8888_32;
         case ColorType.ARGB8888_16:
         {
             byte[] result = new byte[4];
             int i = color.ToArgb();
             ByteConverter.GetBytes((ushort)(i & 0xFFFF)).CopyTo(result, 0);
             ByteConverter.GetBytes((ushort)((i >> 16) & 0xFFFF)).CopyTo(result, 2);
             return result;
         }
         case ColorType.XRGB8888_16:
             color = Color.FromArgb(0, color);
             goto case ColorType.ARGB8888_16;
         case ColorType.ARGB4444:
             return ByteConverter.GetBytes((ushort)(((color.A >> 4) << 12) | ((color.R >> 4) << 8) | ((color.G >> 4) << 4) | (color.B >> 4)));
         case ColorType.RGB565:
             return ByteConverter.GetBytes((ushort)(((color.R >> 3) << 11) | ((color.G >> 2) << 5) | (color.B >> 3)));
     }
     throw new ArgumentOutOfRangeException("type");
 }
Exemplo n.º 2
0
 public int ResolveColor(string aColor)
 {
     if (aColor != null)
     {
         Value v = _parent.MasterScintilla.GetValue(aColor);
         while (v != null)
         {
             aColor = v.val;
             v      = _parent.MasterScintilla.GetValue(aColor);
         }
         // first try known-color string
         System.Drawing.Color c = System.Drawing.Color.FromName(aColor);
         if (c.ToArgb() == 0)
         {
             // didn't find, or is black.
             //hex?
             if (aColor.IndexOf("0x") == 0)
             {
                 return(TO_COLORREF(Int32.Parse(aColor.Substring(2), System.Globalization.NumberStyles.HexNumber)));
             }
             else                     //decimal
             {
                 try
                 {
                     return(TO_COLORREF(Int32.Parse(aColor)));
                 }
                 catch (Exception)
                 {
                 }
             }
         }
         return(TO_COLORREF(c.ToArgb() & 0x00ffffff));
     }
     return(0);
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            System.Drawing.Color c1 = System.Drawing.Color.FromName("Blue");
            Console.Write("c1.ToString() = ");
            Console.WriteLine(c1.ToString());

            object o1 = c1;

            System.Drawing.Color c3 = (System.Drawing.Color)o1;
            Console.Write("((System.Drawing.Color)(object)c1).ToString() = ");
            Console.WriteLine(c3.ToString());


            int n = c1.ToArgb();

            Console.Write("c1.ToArgb() = ");
            Console.WriteLine(n);
            uint n1 = (uint)n;

            Console.Write("(uint)c1.ToArgb() = ");
            Console.WriteLine(n1);
            Energy.Base.Color x = (Energy.Base.Color)(uint) c1.ToArgb();
            var html            = x.ToString();

            Console.Write("(string)(Energy.Base.Color) = ");
            Console.WriteLine(html);
            Energy.Base.Color x1 = new Energy.Base.Color((uint)c1.ToArgb());
            var html1            = x1.ToString();

            Console.Write("new Energy.Base.Color((uint)c.ToArgb()) = ");
            Console.WriteLine(html1);

            Console.ReadLine();
        }
Exemplo n.º 4
0
        protected void boundaryfill4(int seedx, int seedy, Color fcolor, Color bcolor,Bitmap bitmap)
        {
            try
            {
                Queue<Point> pq = new Queue<Point>();
                Color color;
                Point p = new Point();
                Point pt = new Point();
                Point p1 = new Point();
                Point p2 = new Point();
                Point p3 = new Point();
                Point p4 = new Point();
                bitmap.SetPixel(seedx, seedy, fcolor);
                p.X = seedx;
                p.Y = seedy;
                pq.Enqueue(p);
                while (pq.Count > 0)
                {
                    pt = pq.Dequeue();
                    color = bitmap.GetPixel(pt.X, pt.Y - 1);
                    if (color.ToArgb() == bcolor.ToArgb() && color.ToArgb() != fcolor.ToArgb())
                    {
                        bitmap.SetPixel(pt.X, pt.Y - 1, fcolor);
                        p1.X = pt.X;
                        p1.Y = pt.Y - 1;
                        pq.Enqueue(p1);
                    }

                    color = bitmap.GetPixel(pt.X, pt.Y + 1);
                    if (color.ToArgb() == bcolor.ToArgb() && color.ToArgb() != fcolor.ToArgb())
                    {
                        bitmap.SetPixel(pt.X, pt.Y + 1, fcolor);
                        p2.X = pt.X;
                        p2.Y = pt.Y + 1;
                        pq.Enqueue(p2);
                    }

                    color = bitmap.GetPixel(pt.X - 1, pt.Y);
                    if (color.ToArgb() == bcolor.ToArgb() && color.ToArgb() != fcolor.ToArgb())
                    {
                        bitmap.SetPixel(pt.X - 1, pt.Y, fcolor);
                        p3.X = pt.X - 1;
                        p3.Y = pt.Y;
                        pq.Enqueue(p3);
                    }

                    color = bitmap.GetPixel(pt.X + 1, pt.Y);
                    if (color.ToArgb() == bcolor.ToArgb() && color.ToArgb() != fcolor.ToArgb())
                    {
                        bitmap.SetPixel(pt.X + 1, pt.Y, fcolor);
                        p4.X = pt.X + 1;
                        p4.Y = pt.Y;
                        pq.Enqueue(p4);
                    }

                }
            }
            catch { }
        }
        private static List<Rectangle> CreateBoxes(Bitmap image, Rectangle region, Color background)
        {
            List<Rectangle> boxes = new List<Rectangle>();
            Point presentPixel;
            Rectangle newBox;
            int x2 = 0;
            int y2 = 0;
            Color presentColour;

            for (int y = region.Top; y <= region.Bottom; y++)
            {

                for (int x = region.Left; x <= region.Right; x++)
                {
                    if (x > 0 && x < image.Width && y > 0 && y < image.Height)
                    {
                        presentPixel = new Point(x, y);

                        presentColour = image.GetPixel(x, y);

                        if (presentColour.ToArgb() != background.ToArgb())
                        {
                            newBox = new Rectangle(presentPixel, new Size(0, 0));
                            x2 = x;

                            while (x2 < (image.Width - 1) && image.GetPixel(x2, y).ToArgb() != background.ToArgb())
                            {
                                x2 += 1;
                                newBox = new Rectangle(newBox.X, newBox.Y, newBox.Width + 1, newBox.Height);
                            }

                            y2 = y;
                            while (y2 < (image.Height - 1) && image.GetPixel(x2, y2).ToArgb() != background.ToArgb())
                            {
                                y2 += 1;
                                newBox = new Rectangle(newBox.X, newBox.Y, newBox.Width, newBox.Height + 1);
                            }

                            y2 = y + newBox.Height;
                            while (y2 < (image.Height - 1) && image.GetPixel(x, y2).ToArgb() != background.ToArgb())
                            {
                                y2 += 1;
                                newBox = new Rectangle(newBox.X, newBox.Y, newBox.Width, newBox.Height + 1);
                            }

                            boxes.Add(newBox);

                            x += (newBox.Width + 1);
                        }
                    }
                }
            }

            return boxes;
        }
Exemplo n.º 6
0
 private bool IsBackground(System.Drawing.Color color)
 {
     if (SimilarColor((uint)color.ToArgb(), 0xff313129) ||
         SimilarColor((uint)color.ToArgb(), 0xff4c4c36) ||
         SimilarColor((uint)color.ToArgb(), 0xff3e3e2f) ||
         SimilarColor((uint)color.ToArgb(), 0xff37372c) ||
         SimilarColor((uint)color.ToArgb(), 0xffffffff))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
        private void DrawLine(Vector3 from, Vector3 to, Color color)
        {
            var vertices = new List<PositionColored>();

            vertices.Add(new PositionColored(from, color.ToArgb()));
            vertices.Add(new PositionColored(to, color.ToArgb()));

            var buffer = vertices.ToArray();

            SetTarget(Vector3.Zero);

            D3D.Device.DrawUserPrimitives(PrimitiveType.LineStrip, vertices.Count - 1, buffer);
        }
Exemplo n.º 8
0
        public static void DrawLine(Vector3 from, Vector3 to, Color color)
        {
            var vertices = new PositionColored[2];

            vertices[0] = new PositionColored(Vector3.Zero, color.ToArgb());
            from        = from.SwitchYZ();
            to          = to.SwitchYZ();
            vertices[1] = new PositionColored(to - from, color.ToArgb());

            InternalRender(from);

            Drawing.Direct3DDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices.Length / 2, vertices);
        }
        // DrawLine
        private void DrawLine(SlimDX.Vector3 from, SlimDX.Vector3 to, System.Drawing.Color color)
        {
            var vertices = new List <PositionColored>();

            vertices.Add(new PositionColored(from, color.ToArgb()));
            vertices.Add(new PositionColored(to, color.ToArgb()));

            var buffer = vertices.ToArray();

            SetTarget(SlimDX.Vector3.Zero);

            D3D.Device.DrawUserPrimitives(SlimDX.Direct3D9.PrimitiveType.LineStrip, vertices.Count - 1, buffer);
        }
Exemplo n.º 10
0
 public Brush GetSolidBrush(Color c)
 {
     Brush br;
     if (_solidBrushes.TryGetValue(c.ToArgb(), out br))
     {
         return br;
     }
     else
     {
         br = new SolidBrush(c);
         _solidBrushes.Add(c.ToArgb(), br);
         return br;
     }
 }
Exemplo n.º 11
0
        //public LinearGradientBrush(RectangleF rect,
        //                    Color color1,
        //                    Color color2,
        //                    LinearGradientMode mode)
        //{
        //    GpLineGradient brush;

        //    lastResult = GdiPlus.GdipCreateLineBrushFromRect(ref rect,
        //                                                         color1.ToArgb(),
        //                                                         color2.ToArgb(),
        //                                                         mode,
        //                                                         WrapMode.WrapModeTile,
        //                                                         out brush);

        //    SetNativeBrush(brush);
        //}

        //LinearGradientBrush(Rectangle rect,
        //                    Color color1,
        //                    Color color2,
        //                    LinearGradientMode mode)
        //{
        //    GpLineGradient brush;

        //    lastResult = GdiPlus.GdipCreateLineBrushFromRectI(ref rect,
        //                                                          color1.ToArgb(),
        //                                                          color2.ToArgb(),
        //                                                          mode,
        //                                                          WrapMode.WrapModeTile,
        //                                                          out brush);

        //    SetNativeBrush(brush);
        //}

        //LinearGradientBrush(RectangleF rect,
        //                    Color color1,
        //                    Color color2,
        //                    float angle,
        //                    bool isAngleScalable)
        //{
        //    GpLineGradient brush;

        //    lastResult = GdiPlus.GdipCreateLineBrushFromRectWithAngle(ref rect,
        //                                                                  color1.ToArgb(),
        //                                                                  color2.ToArgb(),
        //                                                                  angle,
        //                                                                  isAngleScalable,
        //                                                                  WrapMode.WrapModeTile,
        //                                                                  out brush);

        //    SetNativeBrush(brush);
        //}

        //LinearGradientBrush(Rectangle rect,
        //                    Color color1,
        //                    Color color2,
        //                    float angle,
        //                    bool isAngleScalable)
        //{
        //    GpLineGradient brush = new GpLineGradient();

        //    lastResult = GdiPlus.GdipCreateLineBrushFromRectWithAngleI(ref rect,
        //                                                                   color1.ToArgb(),
        //                                                                   color2.ToArgb(),
        //                                                                   angle,
        //                                                                   isAngleScalable,
        //                                                                   WrapMode.WrapModeTile,
        //                                                                   out brush);

        //    SetNativeBrush(brush);
        //}
        #endregion

        GpStatus SetLinearColors(Color color1,
                                 Color color2)
        {
            return(SetStatus(GdiPlus.GdipSetLineColors((GpLineGradient)nativeBrush,
                                                       color1.ToArgb(),
                                                       color2.ToArgb())));
        }
Exemplo n.º 12
0
        void IPaintTo3D.ClosePath(System.Drawing.Color color)
        {
            Brush br = null;
            Pen   pn = null;

            if (color.ToArgb() == avoidColor.ToArgb())
            {
                br = MakeSolidBrush(Color.FromArgb(255 - avoidColor.R, 255 - avoidColor.G, 255 - avoidColor.B));
            }
            else
            {
                br = MakeSolidBrush(color);
            }
            if (selectMode && selectOnlyOutline)
            {
                pn = MakePen();
                graphics.DrawPath(pn, graphicsPath);
            }
            else
            {
                graphics.FillPath(br, graphicsPath);
            }
            graphicsPath = null; // ab jetzt wieder direkt auf GDI zeichnen
            if (br != null)
            {
                br.Dispose();
            }
            if (pn != null)
            {
                pn.Dispose();
            }
        }
Exemplo n.º 13
0
        public static unsafe void DrawCircle(Location center, float radius, Color innerColor, Color outerColor, int complexity = 24, bool isFilled = true)
        {
            var vertices = new List<PositionColored>();

            if (isFilled)
                vertices.Add(new PositionColored(Vector3.Zero, innerColor.ToArgb()));

            double stepAngle = (Math.PI * 2) / complexity;
            for (int i = 0; i <= complexity; i++)
            {
                double angle = (Math.PI * 2) - (i * stepAngle);
                float x = (float)(radius * Math.Cos(angle));
                float y = (float)(-radius * Math.Sin(angle));
                vertices.Add(new PositionColored(new Vector3(x, y, 0), outerColor.ToArgb()));
            }

            var buffer = vertices.ToArray();

            InternalRender(center.ToVector3() + new Vector3(0, 0, 0.3f));

            if (isFilled)
                Device.DrawUserPrimitives(PrimitiveType.TriangleFan, buffer.Length - 2, buffer);
            else
                Device.DrawUserPrimitives(PrimitiveType.LineStrip, buffer.Length - 1, buffer);
        }
Exemplo n.º 14
0
        private void ClearColorInSheet(Color color)
        {
            if (this.currentSpriteSheet != null)
            {

                int c = color.ToArgb();

                this.currentSpriteSheet.MakeTransparent(color);

                //for (int x = 0; x < this.currentSpriteSheet.Width; x++)
                //{
                //    for (int y = 0; y < this.currentSpriteSheet.Height; y++)
                //    {
                //        if (c.Equals(this.currentSpriteSheet.GetPixel(x, y).ToArgb()))
                //        {
                //            this.currentSpriteSheet.SetPixel(x, y, Color.Transparent);

                //            Color color2 = this.currentSpriteSheet.GetPixel(x, y);
                //        }
                //    }
                //}

                this.sheetPictBx.Refresh();
            }
        }
Exemplo n.º 15
0
 public sColor(int alpha, Color value)
 {
     pName = value.Name;
     pValue = (uint)value.ToArgb();
     pColorAlpha = Color.FromArgb(255 - alpha, value);
     pColor = value;
 }
Exemplo n.º 16
0
        public IImage ModifyAlpha(byte alpha, int removeColor)
        {
            NETImage lwuitImage = new NETImage();

            lwuitImage.image = new Bitmap(image.Width, image.Height);
            lwuitImage.image.SetResolution(96, 96);
            System.Drawing.Color emptyColor = System.Drawing.Color.FromArgb(0);
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    System.Drawing.Color rgb  = image.GetPixel(i, j);
                    System.Drawing.Color rgb1 = System.Drawing.Color.FromArgb(alpha, rgb.R, rgb.G, rgb.B);
                    if ((rgb.ToArgb() & 0xffffff) == removeColor)
                    {
                        lwuitImage.image.SetPixel(i, j, emptyColor);
                    }
                    else
                    {
                        lwuitImage.image.SetPixel(i, j, rgb1);
                    }
                }
            }
            return(lwuitImage);
        }
Exemplo n.º 17
0
        // DrawCircle
        private void DrawCircle(Location loc, float radius, System.Drawing.Color innerColor, System.Drawing.Color outerColor, int complexity = 24, bool isFilled = true)
        {
            var vertices = new List <PositionColored>();

            if (isFilled)
            {
                vertices.Add(new PositionColored(SlimDX.Vector3.Zero, innerColor.ToArgb()));
            }

            double stepAngle = (Math.PI * 2) / complexity;

            for (int i = 0; i <= complexity; i++)
            {
                double angle = (Math.PI * 2) - (i * stepAngle);
                float  x     = (float)(radius * Math.Cos(angle));
                float  y     = (float)(-radius * Math.Sin(angle));

                //vertices.Add(new PositionColored(new SlimDX.Vector3(x, y, 0), outerColor.ToArgb()));

                vertices.Add(new PositionColored(new SlimDX.Vector3(x, y, 0), outerColor.ToArgb()));
            }

            var buffer = vertices.ToArray();

            SetTarget(loc.ToVector3() + new SlimDX.Vector3(0, 0, 0.3f));

            D3D.Device.DrawUserPrimitives(SlimDX.Direct3D9.PrimitiveType.TriangleFan, buffer.Length - 2, buffer);
        }
Exemplo n.º 18
0
        public static void Circle(BitmapData bmpData, int Size, int X, int Y, Color Colour)
        {
            CacheCircles(Size);

            int tempX;
            int i = 0;
            for (int tempY = Y - Size; tempY < Y + Size; tempY++)
            {
                if (tempY >= 0)
                {
                    if (tempY >= bmpData.Height)
                    {
                        break;
                    }
                    tempX = X - CircleCache[Size][i];
                    while (tempX < CircleCache[Size][i] + X)
                    {
                        if (tempX >= 0)
                        {
                            if (tempX >= bmpData.Width)
                            {
                                break;
                            }
                            IntPtr temp = FindPtr(bmpData, tempX, tempY);
                            System.Runtime.InteropServices.Marshal.WriteInt32(temp, Colour.ToArgb());
                        }

                      tempX++;
                    }
                }
                i++;
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Search for a given color within all the client area of BS. Faster then PixelSearch, as it doesn't do a new capture each time. 
 /// </summary>
 /// <param name="left"></param>
 /// <param name="top"></param>
 /// <param name="right"></param>
 /// <param name="bottom"></param>
 /// <param name="color1"></param>
 /// <param name="variation"></param>
 /// <returns></returns>
 public static Point FullScreenPixelSearch(Color color1, int variation, bool forceCapture = false)
 {
     if (!TakeFullScreenCapture(forceCapture)) return Point.Empty;
     int nbMatchMin = 1, xRef = 0, yRef = 0;
     if (FastFindWrapper.GenericColorSearch(1, ref nbMatchMin, ref xRef, ref yRef, color1.ToArgb(), variation, DEFAULT_SNAP) == 0 || nbMatchMin == 0) return Point.Empty;
     return new Point(xRef, yRef);
 }
Exemplo n.º 20
0
        public ColorRange(Color c, int threshold)
        {
            int argb = c.ToArgb();

            from = Color.FromArgb(Math.Max(c.R - threshold, 0), Math.Max(c.G - threshold, 0), Math.Max(c.B - threshold, 0)).ToArgb();
            to = Color.FromArgb(Math.Min(c.R + threshold, 255), Math.Min(c.G + threshold, 255), Math.Min(c.B + threshold, 255)).ToArgb();
        }
        private void binarization(Bitmap imgSrc)
        {
           
            int px; double br;
            double threshold = 0.5;
            
            for (int row = 0; row < height - 1; row++)
            {
                for (int col = 0; col < width - 1; col++)
                {
                    pixel = imgSrc.GetPixel(col, row);
                    px = pixel.ToArgb();
                    br = pixel.GetBrightness();
                    if (pixel.GetBrightness() < threshold)
                    {

                        GreyImage[col, row] = 0;

                    }
                    else
                    {

                        GreyImage[col, row] = 1;
                    }

                }
            }
        }
Exemplo n.º 22
0
        // Map a System.Drawing color into an Xsharp color.
        public static Xsharp.Color DrawingToXColor(System.Drawing.Color color)
        {
            int argb = color.ToArgb();

            return(new Xsharp.Color((argb >> 16) & 0xFF,
                                    (argb >> 8) & 0xFF, argb & 0xFF));
        }
Exemplo n.º 23
0
 public sColor(Color value)
 {
     pName = value.Name;
     pValue = (uint)value.ToArgb();
     pColorAlpha = value;
     pColor      = value;
 }
Exemplo n.º 24
0
 public static void DrawColoredRectangle(Device dev,RectangleF rect,Color color)
 {
     VertexBuffer vb=null;
     IndexBuffer ib=null;
     try{
         int colorArgb=color.ToArgb();
         CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] {
                 new CustomVertex.PositionColored(rect.Left,rect.Bottom,0,colorArgb),
                 new CustomVertex.PositionColored(rect.Left,rect.Top,0,colorArgb),
                 new CustomVertex.PositionColored(rect.Right,rect.Top,0,colorArgb),
                 new CustomVertex.PositionColored(rect.Right,rect.Bottom,0,colorArgb),
             };
         vb=new VertexBuffer(typeof(CustomVertex.PositionColored),
             CustomVertex.PositionColored.StrideSize*quadVerts.Length,
             dev,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed);
         vb.SetData(quadVerts,0,LockFlags.None);
         int[] indicies=new int[] { 0,1,2,0,2,3 };
         ib=new IndexBuffer(typeof(int),indicies.Length,dev,Usage.None,Pool.Managed);
         ib.SetData(indicies,0,LockFlags.None);
         dev.VertexFormat=CustomVertex.PositionColored.Format;
         dev.SetStreamSource(0,vb,0);
         dev.Indices=ib;
         dev.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3);
     }finally{
         if(vb!=null){
             vb.Dispose();
             vb=null;
         }
         if(ib!=null){
             ib.Dispose();
             ib=null;
         }
     }
 }
        public static void ReturnColor(Color c)
        {
            int colorValue = c.ToArgb();

              if( _unusedColors.IndexOf(colorValue) == -1 )
            _unusedColors.Add(colorValue);
        }
        private string GetHtmlColor(System.Drawing.Color color)
        {
            int i_color = color.ToArgb();

            i_color &= 0xFFFFFF;
            return(i_color.ToString("X6"));
        }
Exemplo n.º 27
0
        public void SetModulateColor(sd.Color color)
        {
            //white is really no color at all
            if (color.ToArgb() == sd.Color.White.ToArgb())
            {
                CurrentImageAttributes.ClearColorMatrix(ColorAdjustType.Bitmap);
                return;
            }

            float r = color.R / 255.0f;
            float g = color.G / 255.0f;
            float b = color.B / 255.0f;
            float a = color.A / 255.0f;

            float[][] colorMatrixElements =
            {
                new float[] { r, 0, 0, 0, 0 },
                new float[] { 0, g, 0, 0, 0 },
                new float[] { 0, 0, b, 0, 0 },
                new float[] { 0, 0, 0, a, 0 },
                new float[] { 0, 0, 0, 0, 1 }
            };

            ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

            CurrentImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Draws an image using the specified flags and state on XP systems.
        /// </summary>
        /// <param Name="hdc">Device context to draw to</param>
        /// <param Name="index">Index of image to draw</param>
        /// <param Name="x">X Position to draw at</param>
        /// <param Name="y">Y Position to draw at</param>
        /// <param Name="flags">Drawing flags</param>
        /// <param Name="cx">Width to draw</param>
        /// <param Name="cy">Height to draw</param>
        /// <param Name="foreColor">Fore colour to blend with when using the
        /// ILD_SELECTED or ILD_BLEND25 flags</param>
        /// <param Name="stateFlags">State flags</param>
        /// <param Name="glowOrShadowColor">If stateFlags include ILS_GLOW, then
        /// the colour to use for the glow effect.  Otherwise if stateFlags includes
        /// ILS_SHADOW, then the colour to use for the shadow.</param>
        /// <param Name="saturateColorOrAlpha">If stateFlags includes ILS_ALPHA,
        /// then the alpha component is applied to the icon. Otherwise if
        /// ILS_SATURATE is included, then the (R,G,B) components are used
        /// to saturate the image.</param>
        public void DrawImage(
            IntPtr hdc,
            int index,
            int x,
            int y,
            ImageListDrawItemConstants flags,
            int cx,
            int cy,
            System.Drawing.Color foreColor,
            ImageListDrawStateConstants stateFlags,
            System.Drawing.Color saturateColorOrAlpha,
            System.Drawing.Color glowOrShadowColor
            )
        {
            IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS();

            pimldp.hdcDst = hdc;
            pimldp.cbSize = Marshal.SizeOf(pimldp.GetType());
            pimldp.i      = index;
            pimldp.x      = x;
            pimldp.y      = y;
            pimldp.cx     = cx;
            pimldp.cy     = cy;
            pimldp.rgbFg  = Color.FromArgb(0,
                                           foreColor.R, foreColor.G, foreColor.B).ToArgb();
            Debug.WriteLine(pimldp.rgbFg.ToString());
            pimldp.fStyle = (int)flags;
            pimldp.fState = (int)stateFlags;
            if ((stateFlags & ImageListDrawStateConstants.ILS_ALPHA) ==
                ImageListDrawStateConstants.ILS_ALPHA)
            {
                // Set the alpha:
                pimldp.Frame = (int)saturateColorOrAlpha.A;
            }
            else if ((stateFlags & ImageListDrawStateConstants.ILS_SATURATE) ==
                     ImageListDrawStateConstants.ILS_SATURATE)
            {
                // discard alpha channel:
                saturateColorOrAlpha = Color.FromArgb(0,
                                                      saturateColorOrAlpha.R,
                                                      saturateColorOrAlpha.G,
                                                      saturateColorOrAlpha.B);
                // set the saturate color
                pimldp.Frame = saturateColorOrAlpha.ToArgb();
            }
            glowOrShadowColor = Color.FromArgb(0,
                                               glowOrShadowColor.R,
                                               glowOrShadowColor.G,
                                               glowOrShadowColor.B);
            pimldp.crEffect = glowOrShadowColor.ToArgb();
            if (iImageList == null)
            {
                pimldp.himl = hIml;
                int ret = ImageList_DrawIndirect(ref pimldp);
            }
            else
            {
                iImageList.Draw(ref pimldp);
            }
        }
Exemplo n.º 29
0
        public static Color lighter(Color color, float fraction)
        {
            float factor = (1.0f + fraction);

            int rgb = color.ToArgb();
            int red = (rgb >> 16) & 0xFF;
            int green = (rgb >> 8) & 0xFF;
            int blue = (rgb >> 0) & 0xFF;
            //int alpha = (rgb >> 24) & 0xFF;

            red = (int) (red * factor);
            green = (int) (green * factor);
            blue = (int) (blue * factor);

            if (red < 0) {
                red = 0;
            } else if (red > 255) {
                red = 255;
            }
            if (green < 0) {
                green = 0;
            } else if (green > 255) {
                green = 255;
            }
            if (blue < 0) {
                blue = 0;
            } else if (blue > 255) {
                blue = 255;
            }

            //int alpha = color.getAlpha();

            return Color.FromArgb(red, green, blue);
        }
Exemplo n.º 30
0
        public void SetPixel(int x, int y, System.Drawing.Color colour)
        {
            int index = x + (y * Width);
            int col   = colour.ToArgb();

            Bits[index] = col;
        }
Exemplo n.º 31
0
        /// <summary>
        /// The render method to draw this widget on the screen.
        ///
        /// Called on the GUI thread.
        /// </summary>
        /// <param name="drawArgs">The drawing arguments passed from the WW GUI thread.</param>
        public void Render(DrawArgs drawArgs)
        {
            if (!this.m_isInitialized)
            {
                this.Initialize(drawArgs);
            }

            if ((m_visible) && (m_enabled))
            {
                // Draw the interior background
                WidgetUtilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y,
                    m_size.Width,
                    m_size.Height,
                    0.0f,
                    m_BackgroundColor.ToArgb(),
                    drawArgs.device);

                m_sprite.Begin(SpriteFlags.AlphaBlend);
                m_sprite.Transform  = Matrix.Scaling(this.XScale, this.YScale, 0);
                m_sprite.Transform *= Matrix.Translation(AbsoluteLocation.X + m_size.Width / 2, AbsoluteLocation.Y + m_size.Height / 2, 0);
                m_sprite.Draw(m_iconTexture.Texture,
                              new Vector3(m_iconTexture.Width >> 1, m_iconTexture.Height >> 1, 0),
                              Vector3.Empty,
                              m_normalColor);
                m_sprite.Transform = Matrix.Identity;
                m_sprite.End();

                UpdateCrosshair(drawArgs);
            }
        }
        /// <summary>
        /// Creates a DICOM overlay from a GDI+ Bitmap.
        /// </summary>
        /// <param name="ds">Dataset</param>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="mask">Color mask for overlay</param>
        /// <returns>DICOM overlay</returns>
        public static DicomOverlayData FromBitmap(DicomDataset ds, Bitmap bitmap, Color mask)
        {
            ushort group = 0x6000;
            while (ds.Contains(new DicomTag(group, DicomTag.OverlayBitPosition.Element))) group += 2;

            var overlay = new DicomOverlayData(ds, group)
                              {
                                  Type = DicomOverlayType.Graphics,
                                  Rows = bitmap.Height,
                                  Columns = bitmap.Width,
                                  OriginX = 1,
                                  OriginY = 1,
                                  BitsAllocated = 1,
                                  BitPosition = 1
                              };

            var array = new BitList { Capacity = overlay.Rows * overlay.Columns };

            int p = 0;
            for (var y = 0; y < bitmap.Height; y++)
            {
                for (var x = 0; x < bitmap.Width; x++, p++)
                {
                    if (bitmap.GetPixel(x, y).ToArgb() == mask.ToArgb()) array[p] = true;
                }
            }

            overlay.Data = EvenLengthBuffer.Create(new MemoryByteBuffer(array.Array));

            return overlay;
        }
 internal XLColor(Color color)
 {
     _color = color;
     _hashCode = 13 ^ color.ToArgb();
     HasValue = true;
     _colorType = XLColorType.Color;
 }
        public override string ToString()
        {
            var rgb = Color.ToArgb();
            int r = (rgb >> 16) & 255, g = (rgb >> 8) & 255, b = rgb & 255;

            return(r.ToString("x2") + g.ToString("x2") + b.ToString("x2"));
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="position">Position of the vertex.</param>
 /// <param name="color">Color of the vertex.</param>
 /// <param name="textureCoordinates">Texture coordinates.</param>
 public PositionDiffuse2DTexture1(Vector3 position, Drawing.Color color, Vector2 textureCoordinates)
 {
     // Copy data.
     Position           = position;
     ColorValue         = color.ToArgb();
     TextureCoordinates = textureCoordinates;
 }
Exemplo n.º 36
0
 public Engine_Picture(string fileName, Color colorKey)
 {
     ImageInformation imageInformation = TextureLoader.ImageInformationFromFile(Engine_Game.PicturesPath + fileName);
     m_Width = imageInformation.Width;
     m_Height = imageInformation.Height;
     m_Texture = TextureLoader.FromFile(Engine_Game.Device, Engine_Game.PicturesPath + fileName, 0, 0, 1, Usage.None, Format.Unknown, Pool.Managed, Filter.None, Filter.None, colorKey.ToArgb());
 }
Exemplo n.º 37
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="color"></param>
 public SerializableColor(Color color)
 {
     //this.A = color.A;
     //this.R = color.R;
     //this.G = color.G;
     //this.B = color.B;
     this.Argb = color.ToArgb();
 }
Exemplo n.º 38
0
 public void SetPixel(int x, int y, Color color)
 {
     int pointBase = y * this.size.Width + x;
     if (0 <= pointBase && pointBase < this.array.Length)
     {
         this.array[pointBase] = color.ToArgb();
     }
 }
Exemplo n.º 39
0
 public static string ColorToRGBString(Color color)
 {
     int argb = color.ToArgb();
     int r = (argb >> 16) & 0xff;
     int g = (argb >> 8) & 0xff;
     int b = argb & 0xff;
     return r.ToString("X").PadLeft(2, '0') + g.ToString("X").PadLeft(2, '0') + b.ToString("X").PadLeft(2, '0');
 }
Exemplo n.º 40
0
 public static string ToHtml(System.Drawing.Color color)
 {
     if (System.Drawing.Color.Transparent == color)
     {
         return("Transparent");
     }
     return(string.Concat("#", (color.ToArgb() & 0x00FFFFFF).ToString("X6")));
 }
Exemplo n.º 41
0
 /// <summary>
 /// Agregar triangulo al batch
 /// </summary>
 public void addTriangle(Vector3 a, Vector3 b, Vector3 c, Color color)
 {
     int cInt = color.ToArgb();
     addTriangle(
         new CustomVertex.PositionColored(a, cInt), 
         new CustomVertex.PositionColored(b, cInt), 
         new CustomVertex.PositionColored(c, cInt));
 }
Exemplo n.º 42
0
        public GpStatus SetCenterColor(Color color)
        {
            SetStatus(GdiPlus.GdipSetPathGradientCenterColor(
                          (GpPathGradient)nativeBrush,
                          color.ToArgb()));

            return(lastResult);
        }
Exemplo n.º 43
0
 /// <summary>
 /// Sets the Windows DWM color.
 /// </summary>
 /// <param name="newColor">The color to set.</param>
 public static void SetColor(Color newColor)
 {
     DwmColorParams p = new DwmColorParams();
     DwmpGetColorizationParameters(out p);
     p.ColorizationColor = (uint)newColor.ToArgb();
     p.ColorizationAfterglow = p.ColorizationColor;
     DwmpSetColorizationParameters(ref p, true);
 }
Exemplo n.º 44
0
        public SolidBrushPlus(Color color)
        {
            GpSolidFill brush;

            lastResult = GdiPlus.GdipCreateSolidFill(color.ToArgb(), out brush);

            SetNativeBrush(brush);
        }
Exemplo n.º 45
0
 public ChannelMapperChannel(int channel, int location, Color color, string name, bool enabled)
 {
     Number = channel;
     Location = location;
     Color = color.ToArgb();
     Name = name;
     Enabled = enabled;
 }
        public void SetBackgroundColor(Color color)
        {
            string c = color.IsNamedColor ? color.Name : string.Format("#{0:X8}", color.ToArgb());

            _builder.AppendFormat("{{bg:{0}}}", c);
            if (_writeToTrace)
                Trace.Write(string.Format("{{bg:{0}}}", c));
        }
Exemplo n.º 47
0
 public static void AdminMsg(string Msg, Color Color)
 {
     foreach (Client i in ClientManager.GetClients()) {
         if (i.IsPlaying() && Ranks.IsAllowed(i, Enums.Rank.Moniter)) {
             SendDataTo(i, TcpPacket.CreatePacket("msg", Msg, Color.ToArgb().ToString()));
         }
     }
 }
Exemplo n.º 48
0
		public Pen(Color color, float width) {
			if (width < 1.0f) {
				width = 1.0f;
			}
			this.color = color;
			this.width = width;
			native = LibIGraph.CreatePen_Color(width, color.ToArgb());
		}
Exemplo n.º 49
0
 /// <summary>
 /// See <see cref="INonIndexedPixel.SetColor"/> for more details.
 /// </summary>
 public void SetColor(Color color)
 {
     Int32 argb = color.ToArgb();
     alpha = (argb >> Pixel.AlphaShift) > Pixel.ByteMask ? Pixel.Zero : Pixel.One;
     red = (Byte) (argb >> Pixel.RedShift);
     green = (Byte) (argb >> Pixel.GreenShift);
     blue = (Byte) (argb >> Pixel.BlueShift);
 }
Exemplo n.º 50
0
        public ColorRange(Color c1, Color c2)
        {
            int argbFrom = c1.ToArgb();
            int argbTo = c2.ToArgb();

            from = Math.Min(argbFrom, argbTo);
            to = Math.Max(argbFrom, argbTo);
        }
Exemplo n.º 51
0
        public void DrawBigText(float x, float y, string text, int color)
        {
            //normalize color since text is picky
            System.Drawing.Color a = System.Drawing.Color.FromArgb(color);
            System.Drawing.Color c = System.Drawing.Color.FromArgb(a.R, a.G, a.B);

            mGoodFont.DrawText(null, text, new System.Drawing.Rectangle((int)x, (int)y, 0, 0),
                               DrawTextFormat.NoClip, c.ToArgb());
        }
Exemplo n.º 52
0
        private void tbc_colorAlpha_EditValueChanged(object sender, EventArgs e)
        {
            int num = Convert.ToInt32(this.tbc_colorAlpha.Value);

            System.Drawing.Color color = System.Drawing.Color.FromArgb(num, this.ce_color.Color.R, this.ce_color.Color.G, this.ce_color.Color.B);
            uint shadowColor           = (uint)color.ToArgb();

            this._3DControl.SunConfig.ShadowColor = shadowColor;
        }
Exemplo n.º 53
0
        internal static Color4 ToColor4(this System.Drawing.Color color)
        {
            uint argb = (uint)color.ToArgb();
            uint abgr =
                (argb & 0xff00ff00) |       //alpha and green stay in place
                ((argb >> 16) & 0xff) |     //red goes down 16 bits
                ((argb & 0xff) << 16);      //blue goes up 16 bits

            return(new Color4(abgr));
        }
Exemplo n.º 54
0
        public void SetColor(int index, System.Drawing.Color color)
        {
            StringCollection sc = Default.SeriesColors;

            while (index >= sc.Count)
            {
                sc.Add("Black");
            }
            sc[index] = color.ToArgb().ToString();
        }
Exemplo n.º 55
0
        /// <summary> Draw outlined box.</summary>
        /// <remarks> Nesox, 2013-12-28.</remarks>
        /// <param name="center"> The min. </param>
        /// <param name="length"> The length. </param>
        /// <param name="width">  The width. </param>
        /// <param name="height"> The height. </param>
        /// <param name="color">  The color. </param>
        public static void DrawOutlinedBox(Vector3 center, float length, float width, float height, Color color)
        {
            float w = width / 2;
            float h = height / 2;
            float d = length / 2;

            Matrix mat = Matrix.Identity * Matrix.Scaling(w, d, h) * Matrix.Translation(center);

            Device.SetTransform(TransformState.World, mat);

            var min = new Vector3(-1, -1, 0);
            var max = new Vector3(1, 1, 1);

            var vtx = new[]
            {
                new ColoredVertex(new Vector3(min.X, max.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, max.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(min.X, min.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, min.Y, max.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(min.X, min.Y, min.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, min.Y, min.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(min.X, max.Y, min.Z), color.ToArgb()),
                new ColoredVertex(new Vector3(max.X, max.Y, min.Z), color.ToArgb())
            };

            var ind = new short[]
            {
                //Top           [_]
                0, 1, 1, 3,
                3, 2, 2, 0,
                //Bottom        [_]
                6, 7, 7, 5,
                5, 4, 4, 6,
                // Back         | |
                0, 6, 1, 7,
                // Front        | |
                2, 4, 3, 5,
                // Left         | |
                0, 6, 2, 4,
                // Right        | |
                1, 7, 3, 5
            };

            var oldDecl = Device.VertexDeclaration;

            using (var newDecl = ColoredVertex.GetDecl(Device))
            {
                Device.VertexDeclaration = newDecl;
                Device.DrawIndexedUserPrimitives(PrimitiveType.LineList, 0, 8, 12, ind, Format.Index16, vtx, 16);
                Device.VertexDeclaration = oldDecl;
            }
        }
Exemplo n.º 56
0
        /// <summary>
        /// Draws an image using the specified flags and state on XP systems.
        /// </summary>
        /// <param name="hdc">Device context to draw to</param>
        /// <param name="index">Index of image to draw</param>
        /// <param name="x">X Position to draw at</param>
        /// <param name="y">Y Position to draw at</param>
        /// <param name="flags">Drawing flags</param>
        /// <param name="cx">Width to draw</param>
        /// <param name="cy">Height to draw</param>
        /// <param name="foreColor">Fore colour to blend with when using the ILD_SELECTED or ILD_BLEND25 flags</param>
        /// <param name="stateFlags">State flags</param>
        /// <param name="saturateColorOrAlpha">If stateFlags includes ILS_ALPHA, then the alpha component is applied to the icon. Otherwise if
        /// ILS_SATURATE is included, then the (R,G,B) components are used to saturate the image.</param>
        /// <param name="glowOrShadowColor">If stateFlags include ILS_GLOW, then the colour to use for the glow effect.  Otherwise if stateFlags includes
        /// ILS_SHADOW, then the colour to use for the shadow.</param>
        public void DrawImage(
            IntPtr hdc,
            int index,
            int x,
            int y,
            ImageListDrawItemConstants flags,
            int cx,
            int cy,
            System.Drawing.Color foreColor,
            ImageListDrawStateConstants stateFlags,
            System.Drawing.Color saturateColorOrAlpha,
            System.Drawing.Color glowOrShadowColor)
        {
            IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS();

            pimldp.HdcDst        = hdc;
            pimldp.Size          = Marshal.SizeOf(pimldp.GetType());
            pimldp.Index         = index;
            pimldp.X             = x;
            pimldp.Y             = y;
            pimldp.CX            = cx;
            pimldp.CY            = cy;
            pimldp.ForegroundRgb = Color.FromArgb(0, foreColor.R, foreColor.G, foreColor.B).ToArgb();
            pimldp.Style         = (int)flags;
            pimldp.State         = (int)stateFlags;
            if ((stateFlags & ImageListDrawStateConstants.ILS_ALPHA) == ImageListDrawStateConstants.ILS_ALPHA)
            {
                // Set the alpha
                pimldp.Frame = saturateColorOrAlpha.A;
            }
            else if ((stateFlags & ImageListDrawStateConstants.ILS_SATURATE) == ImageListDrawStateConstants.ILS_SATURATE)
            {
                // discard alpha channel:
                saturateColorOrAlpha = Color.FromArgb(0, saturateColorOrAlpha.R, saturateColorOrAlpha.G, saturateColorOrAlpha.B);

                // set the saturate color
                pimldp.Frame = saturateColorOrAlpha.ToArgb();
            }

            glowOrShadowColor = Color.FromArgb(0, glowOrShadowColor.R, glowOrShadowColor.G, glowOrShadowColor.B);

            pimldp.Effect = glowOrShadowColor.ToArgb();

            if (this.imageList == null)
            {
                pimldp.Himl = this.himl;

                int ret = ImageList_DrawIndirect(ref pimldp);
            }
            else
            {
                this.imageList.Draw(ref pimldp);
            }
        }
Exemplo n.º 57
0
        /// <summary>
        /// Replaces pixels with an alpha of 0 to the desired color
        /// </summary>
        /// <param name="transparencyKey">The color that will replace transparent pixels</param>
        public static void ReplaceTransparentPixels(System.Drawing.Bitmap image, System.Drawing.Color transparencyKey)
        {
            var data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, image.PixelFormat);

            try
            {
                int length = data.Height * data.Stride,
                    bypp   = data.Stride / data.Width,
                    key    = transparencyKey.ToArgb();
                if (bypp != 4) //32-bit
                {
                    throw new BadImageFormatException("PixelFormat is not 32-bit");
                }
                var scan0  = data.Scan0;
                var buffer = new int[length / bypp];

                Marshal.Copy(scan0, buffer, 0, buffer.Length);
                int i = 0;

                foreach (var px in buffer)
                {
                    if (px >> 24 == 0)
                    {
                        buffer[i] = key;
                    }
                    ++i;
                }

                Marshal.Copy(buffer, 0, scan0, buffer.Length);

                #region Unsafe version

                //unsafe
                //{
                //    int length = bd.Height * bd.Stride,
                //        bypp = bd.Stride / bd.Width;
                //    int* scan0 = (int*)bd.Scan0.ToPointer();

                //    for (var ofs = 0; ofs < length; ofs += bypp)
                //    {
                //        if ((*scan0 & 0xFF000000L) == 0L)
                //            *scan0 = key;

                //        scan0++;
                //    }
                //}

                #endregion
            }
            finally
            {
                image.UnlockBits(data);
            }
        }
Exemplo n.º 58
0
 private void colorPickEdit1_EditValueChanged(object sender, EventArgs e)
 {
     System.Drawing.Color color = this.colorPickEdit1.Color;
     this.colorPickEdit1.Color = System.Drawing.Color.FromArgb(this.trackBarControl1.Value, color.R, color.G, color.B);
     System.Drawing.Color color1 = System.Drawing.Color.FromArgb(this.trackBarControl1.Value, color.R, color.G, color.B);
     if (app == null || app.Current3DMapControl == null)
     {
         return;
     }
     app.Current3DMapControl.SunConfig.ShadowColor = (uint)color1.ToArgb();
 }
Exemplo n.º 59
0
Arquivo: Utils.cs Projeto: mo5h/omeo
        public static Color ColorFromString(string str)
        {
            Color color = Color.FromName(str);

            if (color.ToArgb() == 0)
            {
                int argb = Int32.Parse(str, NumberStyles.HexNumber);
                color = Color.FromArgb(argb);
            }
            return(color);
        }
Exemplo n.º 60
0
        public static string ConvertColor2Hex(Color argcolor)
        {
            string ret = Convert.ToString(argcolor.ToArgb(), 16);
            int    len = ret.Length;

            for (int i = 0; i < 8 - len; i++)
            {
                ret = "0" + ret;
            }
            return("#" + ret);
        }