SetColorKey() public method

public SetColorKey ( Color clrLow, Color clrHigh ) : void
clrLow Color
clrHigh Color
return void
Example #1
0
        // ctor
        public Tasklist()
        {
            // init colors
            this.BackColor = Const.BackColor;
            this.ForeColor = Const.CaptionColor;

            // gdi objects
            CreateGdiObjects();

            // state icons
            m_icons = new Bitmap[5];
            m_icons[0] = LoadImage("new.bmp");
            m_icons[1] = LoadImage("inProcess.bmp");
            m_icons[2] = LoadImage("complete.bmp");
            m_icons[3] = LoadImage("fail.bmp");
            m_icons[4] = LoadImage("cancelled.bmp");

            // need to draw transparent
            m_iconAttributes = new ImageAttributes();
            m_iconAttributes.SetColorKey(Color.Yellow, Color.Yellow);

            // store list of task items
            m_list = new ArrayList();

            // scroll bar
            m_scrollBar = new VScrollBar();
            m_scrollBar.Bounds = new Rectangle(0, 0, 4, 100);
            m_scrollBar.ValueChanged += new System.EventHandler(this.scrollBar_ValueChanged);
            this.Controls.Add(m_scrollBar);
        }
Example #2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     ImageAttributes attributes = new ImageAttributes();
     Color clr = ((Bitmap)this.Image).GetPixel(0, 0);
     attributes.SetColorKey(clr, clr);
     e.Graphics.DrawImage(this.Image, new Rectangle((this.Width - this.Image.Width) / 2, (this.Height - this.Image.Height) / 2, this.Image.Width, this.Image.Height), 0, 0, this.Image.Width, this.Image.Height, GraphicsUnit.Pixel, attributes);
 }
Example #3
0
        public override void Draw()
        {
            Bitmap DropImage = new Bitmap(GameResources.Instance.DropImage);

            ImageAttributes attr = new ImageAttributes();
            attr.SetColorKey(DropImage.GetPixel(0, 0), DropImage.GetPixel(0, 0));

            Game.Instance.Canvas.DrawImage(DropImage, new Rectangle(left, top, width, height), 0, 0, DropImage.Width, DropImage.Height, GraphicsUnit.Pixel, attr);
        }
Example #4
0
        static BigButton()
        {
            _MagentaKiller = new ImageAttributes();
              _MagentaKiller.SetColorKey(Color.Magenta, Color.Magenta);

              _Font = new Font(
            FontFamily.GenericSansSerif, 12, FontStyle.Bold
              );
        }
Example #5
0
 private void drawIcon(Graphics g)
 {
     // set image attributes
     ImageAttributes attrs = new ImageAttributes();
     //attrs.SetColorKey(icon.GetPixel(0, 0), icon.GetPixel(0, 0));
     attrs.SetColorKey(Color.Transparent, Color.Transparent);
     Rectangle rDest = new Rectangle(0, 0, icon.Width, icon.Height);
     // Draws the image
     g.DrawImage(icon, rDest, 0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel, attrs);
 }
 public RuntimeImageProcessor(BookRenamedEvent bookRenamedEvent)
 {
     _bookRenamedEvent = bookRenamedEvent;
     _originalPathToProcessedVersionPath = new ConcurrentDictionary<string, string>();
     _imageFilesToReturnUnprocessed = new ConcurrentDictionary<string, bool>();
     _cacheFolder = Path.Combine(Path.GetTempPath(), "Bloom");
     _bookRenamedEvent.Subscribe(OnBookRenamed);
     _convertWhiteToTransparent = new ImageAttributes();
     _convertWhiteToTransparent.SetColorKey(Color.FromArgb(253, 253, 253), Color.White);
 }
Example #7
0
 protected override void OnPaint(PaintEventArgs e)
 {
     Graphics g = e.Graphics;
     g.Clear(BackColor);
     // set image attributes
     ImageAttributes attrs = new ImageAttributes();
     attrs.SetColorKey(Color.Transparent, Color.Transparent);
     Rectangle rDest = new Rectangle(0, 0, Image.Width, Image.Height);
     // Draws the image
     g.DrawImage(Image, rDest, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, attrs);
 }
Example #8
0
        /// <summary>
        /// Instanciates a new Sprite class.
        /// </summary>
        public Sprite()
        {
            x = 0;
            y = 0;
            spriteSize = new Size(0, 0);
            collitionPoint = new Point(0, 0);
            collitionRectangle = new Rectangle(x, y, spriteSize.Width, spriteSize.Height);

            imgAttribs = new ImageAttributes();
            imgAttribs.SetColorKey(Color.FromArgb(0, 66, 173), Color.FromArgb(0, 66, 173));
        }
 protected override void DrawContent(ControlGraphicsInfoArgs info)
 {
     info.Graphics.FillRectangle(info.Cache.GetSolidBrush(Color.White), info.ViewInfo.ClientRect);
     var icon = ((QuickHideEditViewInfo)info.ViewInfo).GetIcon;
     if (icon.Image == null)
     {
         icon.Image = Resources.Customization;
     }
     var attr = new ImageAttributes();
     attr.SetColorKey(icon.TransperentColor, icon.TransperentColor);
     info.Graphics.DrawImageUnscaled(icon.Image, info.ViewInfo.ClientRect);
 }
Example #10
0
        public XyPad(Skin skin)
            : base(skin)
        {
            AdditionalProperty propSpeed = new AdditionalProperty();
              propSpeed.Name = "speed";
              propSpeed.Label = "Speed";
              propSpeed.Min = 0;
              propSpeed.Max = 10;
              propSpeed.Value = 0;
              _Config.AdditionalProperties.Add(propSpeed);

              AdditionalProperty propRestX = new AdditionalProperty();
              propRestX.Name = "restx";
              propRestX.Label = "Rest X";
              propRestX.Min = 0;
              propRestX.Max = 127;
              propRestX.Value = 64;
              _Config.AdditionalProperties.Add(propRestX);

              AdditionalProperty propRestY = new AdditionalProperty();
              propRestY.Name = "resty";
              propRestY.Label = "Rest Y";
              propRestY.Min = 0;
              propRestY.Max = 127;
              propRestY.Value = 64;
              _Config.AdditionalProperties.Add(propRestY);

              _Config.CCMeaning = "X";
              _Config.CC2Meaning = "Y";

              BackToRest = new Timer();
              BackToRest.Interval = 20;
              BackToRest.Tick += new EventHandler(BackToRest_Tick);

              Width = 138;
              Height = 138;

              _BackBrush = new SolidBrush(Color.Black);
              _SelBrush = new SolidBrush(Color.Red);
              _BackRect = new Rectangle(1, 11, Width-2, 127);
              _SelRect = new Rectangle(1, 30, 34, 30);
              _Value = 64;
              _Value2 = 64;
              CalcSelRect();

              _MagentaKiller = new ImageAttributes();
              _MagentaKiller.SetColorKey(Color.Magenta, Color.Magenta);

              this.MouseDown += new MouseEventHandler(OnMouseDown);
              this.MouseMove += new MouseEventHandler(OnMouseMove);
              this.MouseUp += new MouseEventHandler(OnMouseUp);
              CalcSelRect();
        }
Example #11
0
        public testForm()
        {
            InitializeComponent();

            noise = new NoiseGenerator((int)DateTime.Now.Ticks);

            planetGfx = panel1.CreateGraphics();
            surfaceGfx = panel2.CreateGraphics();

            imageAttributes = new ImageAttributes();
            imageAttributes.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255));
        }
		private void DrawPanelPaint(object sender, System.Windows.Forms.PaintEventArgs e)
		{

			Graphics g = e.Graphics;
			Brush b = null;
			Pen p = null;

			try			// never want to die in here
			{
				b = new SolidBrush(this.Enabled? this.BackColor: Color.LightGray);
				g.FillRectangle(b, e.ClipRectangle);
				if (bIn && this.Enabled)
					g.DrawRectangle(Pens.Blue, 0, 0, this.Width-1, this.Height-1);

				if (this.Image != null)
				{
					int x = (this.Width - this.Image.Width) / 2;
					int y = (this.Height - this.Image.Height) / 2;
					if (bDown && bIn)
					{
						x += 1;
						y += 1;
					}

					// Draw System.Drawing.Image using the transparency color
					ImageAttributes imageAttr = new ImageAttributes();
					imageAttr.SetColorKey(_Transparency, _Transparency,
						ColorAdjustType.Default);

					g.DrawImage(this.Image,         // System.Drawing.Image
						new System.Drawing.Rectangle(x, y, this.Image.Width, this.Image.Height),    // Dest. rect.
						0,							// srcX
						0,							// srcY
						this.Image.Width,           // srcWidth
						this.Image.Height,          // srcHeight
						GraphicsUnit.Pixel,			// srcUnit
						imageAttr);					// ImageAttributes
				}
				else
				{
					StringFormat format = new StringFormat(StringFormatFlags.NoWrap);
					g.DrawString(this.Text, this.Font, Brushes.Black, new System.Drawing.Rectangle(2, 2, this.Width, this.Height), format);
				}
			}
			catch {}	// todo draw the error message
			finally
			{
				if (b != null)
					b.Dispose();
				if (p != null)
					p.Dispose();
			}
		}
Example #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (e != null)
            {
                e.Graphics.FillRectangle(SystemBrushes.Control, e.ClipRectangle);
                if (arrowsImage != null)
                    e.Graphics.DrawImage(arrowsImage, e.ClipRectangle,
                        new Rectangle(e.ClipRectangle.X * scale_coeff,
                            e.ClipRectangle.Y * scale_coeff,
                            e.ClipRectangle.Width * scale_coeff,
                            e.ClipRectangle.Height * scale_coeff), GraphicsUnit.Pixel);

                if (graph != null)

                    for (int i = graph.VertexCount - 1; i >= 0; i--)
                        if (/*i != movingIndex &&*/
                            chargesScaled[i].y - Charge.radius <= e.ClipRectangle.Bottom &&
                            chargesScaled[i].y + Charge.radius >= e.ClipRectangle.Top &&
                            chargesScaled[i].x - Charge.radius <= e.ClipRectangle.Right &&
                            chargesScaled[i].x + Charge.radius >= e.ClipRectangle.Left
                            )
                        {
                        //if (VertexLayers[i].UseTransparentcy)
                        //{
                            using (ImageAttributes imageAttributes = new ImageAttributes())
                            {
                                imageAttributes.SetColorKey(TransparentColor, TransparentColor);
                                e.Graphics.DrawImage(
                                    vertexImage[i],
                                    new Rectangle(chargesScaled[i].x - Charge.radius,
                                                  chargesScaled[i].y - Charge.radius,
                                                  Charge.radius * 2,
                                                  Charge.radius * 2),
                                    0, 0, Charge.radius * 2 * scale_coeff + 4, Charge.radius * 2 * scale_coeff + 4,
                                    GraphicsUnit.Pixel,
                                    imageAttributes
                                    );
                            }
                        //}
                        //else
                        //{
                        //e.Graphics.DrawImage(vertexImage[i],
                        //    chargesScaled[i].x - Charge.radius,
                        //    chargesScaled[i].y - Charge.radius,
                        //    Charge.radius * 2,
                        //    Charge.radius * 2);
                        ////}
                    }
            }
        }
Example #14
0
        public PushButton(Skin skin)
            : base(skin)
        {
            Width = 36;
              Height = 45;

              _BlackBrush = new SolidBrush(Color.Black);

              _MagentaKiller = new ImageAttributes();
              _MagentaKiller.SetColorKey(Color.Magenta, Color.Magenta);

              this.MouseDown += new MouseEventHandler(OnMouseDown);
              InitGraphics();
        }
Example #15
0
        private void Chart1_PostPaint(object sender, ChartPaintEventArgs e)
        {
            // Painting series object
            if(e.ChartElement is Series)
            {
                // Add custom painting only to the series with name "Series2"
                Series series = (Series)e.ChartElement;
                if(series.Name == "Series2" && series.Tag == null)
                {
                    // Find data point with maximum Y value
                    DataPoint	dataPoint = series.Points.FindMaxByValue();

                    // Load bitmap from file
                    System.Drawing.Image bitmap = Bitmap.FromFile(this.Page.MapPath("money.png"));

                    // Set White color as transparent
                    ImageAttributes attrib = new ImageAttributes();
                    attrib.SetColorKey(Color.White, Color.White, ColorAdjustType.Default);

                    // Calculates marker position depending on the data point X and Y values
                    RectangleF	imagePosition = RectangleF.Empty;
                    imagePosition.X = (float)e.ChartGraphics.GetPositionFromAxis(
                        "Chart Area 1", AxisName.X, dataPoint.XValue);
                    imagePosition.Y = (float)e.ChartGraphics.GetPositionFromAxis(
                        "Chart Area 1", AxisName.Y, dataPoint.YValues[0]);
                    imagePosition = e.ChartGraphics.GetAbsoluteRectangle(imagePosition);
                    imagePosition.Width = bitmap.Width;
                    imagePosition.Height = bitmap.Height;
                    imagePosition.Y -= bitmap.Height;
                    imagePosition.X -= bitmap.Width /2;

                    // Draw image
                    e.ChartGraphics.Graphics.DrawImage(bitmap,
                        Rectangle.Round(imagePosition),
                        0, 0, bitmap.Width, bitmap.Height,
                        GraphicsUnit.Pixel,
                        attrib);

                    // Add a custom map area in the coordinates of the image
                    RectangleF	rect = e.ChartGraphics.GetRelativeRectangle(imagePosition);

                    MapArea area = new MapArea("Maximum Y value marker. Y = " + dataPoint.YValues[0], "money.htm", "target=\"_blank\"", String.Empty, rect, null);
                    Chart1.MapAreas.Add(area);
                    // Dispose image object
                    bitmap.Dispose();

                    series.Tag = true;
                }
            }
        }
Example #16
0
        public void drawMap(Graphics g, int width, int height, Point center)
        {
            try
            {
                int nScale = mapview.Getlevel(tlVectorControl1.ScaleRatio);
                if (nScale == -1)
                    return;
                LongLat longlat = LongLat.Empty;
                //�������ĵ㾭γ��

                longlat = mapview.OffSet(mapview.ZeroLongLat, mapview.Getlevel(1), center.X, center.Y);
                ImageAttributes imageA = new ImageAttributes();
                longlat = mapview.OffSetZero(-(int)(center.X * tlVectorControl1.ScaleRatio), -(int)(center.Y * tlVectorControl1.ScaleRatio));

                int chose = Convert.ToInt32(ConfigurationSettings.AppSettings.Get("chose"));
                if (chose == 1)
                {
                    g.Clear(Color.White);//ColorTranslator.FromHtml("#EBEAE8")

                    Color color = ColorTranslator.FromHtml("#EBEAE8");
                    imageA.SetColorKey(color, color);
                }
                else if (chose == 2)
                {

                    Color color = ColorTranslator.FromHtml("#F4F4FB");
                    Color color2 = ColorTranslator.FromHtml("#EFF0F1");//EFF0F1
                    //imageAttributes2.SetColorKey(color, color);
                    //imageAttributes2.SetColorKey(color2, color2);
                    imageA.SetColorKey(color2, color);
                }
                //imageA.
                //g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    mapview.Paint(g, width, height, nScale, longlat.Longitude, longlat.Latitude, imageA);
                //���Ʊ�����
                Point p1 = new Point(20, height - 30);
                Point p2 = new Point(20, height - 20);
                Point p3 = new Point(80, height - 20);
                Point p4 = new Point(80, height - 30);

                //g.DrawLines(new Pen(Color.Black, 2), new Point[4] { p1, p2, p3, p4 });
                //string str1 = string.Format("{0}����", MapViewObj.GetMiles(nScale));
                //g.DrawString(str1, new Font("����", 10), Brushes.Black, 30, height - 40);

            }
            catch (Exception e1)
            {
            }
        }
Example #17
0
        private void Chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            // Painting series object
            if(e.ChartElement is System.Windows.Forms.DataVisualization.Charting.Series)
            {
                // Add custom painting only to the series with name "Sereis2"
                Series	series = (Series)e.ChartElement;
                if(series.Name == "Series2")
                {
                    // Find data point with maximum Y value
                    DataPoint	dataPoint = series.Points.FindMaxByValue();

                    // Image path
                    System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm)this.ParentForm;
                    string fileNameString = mainForm.applicationPath + "\\Images\\money.png";

                    // Load bitmap from file
                    System.Drawing.Image bitmap = Bitmap.FromFile(fileNameString);

                    // Set Red color as transparent
                    ImageAttributes attrib = new ImageAttributes();
                    attrib.SetColorKey(Color.Red, Color.Red, ColorAdjustType.Default);

                    // Calculates marker position depending on the data point X and Y values
                    RectangleF	imagePosition = RectangleF.Empty;
                    imagePosition.X = (float)e.ChartGraphics.GetPositionFromAxis(
                        "Default", AxisName.X, dataPoint.XValue);
                    imagePosition.Y = (float)e.ChartGraphics.GetPositionFromAxis(
                        "Default", AxisName.Y, dataPoint.YValues[0]);
                    imagePosition = e.ChartGraphics.GetAbsoluteRectangle(imagePosition);
                    imagePosition.Width = bitmap.Width;
                    imagePosition.Height = bitmap.Height;
                    imagePosition.Y -= bitmap.Height;
                    imagePosition.X -= bitmap.Width /2;

                    // Draw image
                    e.ChartGraphics.Graphics.DrawImage(bitmap,
                        Rectangle.Round(imagePosition),
                        0, 0, bitmap.Width, bitmap.Height,
                        GraphicsUnit.Pixel,
                        attrib);

                    // Dispose image object
                    bitmap.Dispose();
                }
            }
        }
Example #18
0
        public void Paint(Graphics gx)
        {
            if (timeAnimation.Enabled)
            {
                int x = (start.X - 20);
                Move(x);
            }

            ImageAttributes attrib = new ImageAttributes();
            Color color = GetTransparentColor(image);
            attrib.SetColorKey(color, color);

            if (!pushed || imageDown == null)
                gx.DrawImage(image, clientArea, 0, 0, clientArea.Width, clientArea.Height, GraphicsUnit.Pixel, attrib);
            else
                gx.DrawImage(imageDown, clientArea, 0, 0, clientArea.Width, clientArea.Height, GraphicsUnit.Pixel, attrib);
        }
Example #19
0
        public PushButton(Skin skin)
            : base(skin)
        {
            _Config.CCMeaning = "normal";
              _Config.CC2Meaning = "inverted";

              Width = 36;
              Height = 45;

              _BlackBrush = new SolidBrush(Color.Black);

              _MagentaKiller = new ImageAttributes();
              _MagentaKiller.SetColorKey(Color.Magenta, Color.Magenta);

              this.MouseDown += new MouseEventHandler(OnMouseDown);
              InitGraphics();
        }
Example #20
0
        public Fader(Skin skin)
            : base(skin)
        {
            Width = 36;
              Height = 138;

              _BackBrush = new SolidBrush(Color.Black);
              _SelBrush = new SolidBrush(Color.Red);
              _BackRect = new Rectangle(1, 11, Width-2, 127);
              _SelRect = new Rectangle(1, 20, Width-2, 30);

              _MagentaKiller = new ImageAttributes();
              _MagentaKiller.SetColorKey(Color.Magenta, Color.Magenta);

              this.MouseDown += new MouseEventHandler(OnMouseDown);
              this.MouseMove += new MouseEventHandler(OnMouseMove);
              this.MouseUp += new MouseEventHandler(OnMouseUp);
              CalcSelRect();
        }
Example #21
0
        public void Draw()
        {
            Image MenuImage = null;

            // Draw Menu
            switch (MenuState)
            {
                case 0:
                    MenuImage = GameResources.Instance.MainMenu1Image;
                    break;
                case 1:
                    MenuImage = GameResources.Instance.MainMenu2Image;
                    break;
            }

            ImageAttributes attr = new ImageAttributes();
            Bitmap TmpBitmap = new Bitmap(MenuImage);
            attr.SetColorKey(TmpBitmap.GetPixel(0, 0), TmpBitmap.GetPixel(0, 0));

            Rectangle MenuPlacement = new Rectangle(
                (Game.Instance.GameScreen.Width - MenuImage.Width) / 2,
                (Game.Instance.GameScreen.Height - MenuImage.Height) / 2,
                MenuImage.Width,
                MenuImage.Height);

            Game.Instance.Canvas.DrawImage(MenuImage, MenuPlacement, 0, 0, MenuImage.Width, MenuImage.Height, GraphicsUnit.Pixel, attr);

            // Draw selector
            switch (MenuState)
            {
                case 0:
                    Image PointerImage = GameResources.Instance.MainMenuPointerImage;
                    Rectangle SelectorPlacement = new Rectangle(
                        MenuPlacement.Left - PointerImage.Width - 10,
                        MenuPlacement.Top + 90 + ((MenuSelection - 1) * 40),
                        PointerImage.Width,
                        PointerImage.Height);

                    Game.Instance.Canvas.DrawImage(PointerImage, SelectorPlacement, 0, 0, PointerImage.Width, PointerImage.Height, GraphicsUnit.Pixel, attr);
                    break;
            }
        }
Example #22
0
        public GFXEngine(MainForm drawingSurface, int viewAreaWidth, int viewAreaHeight)
        {
            this.mainWindow = drawingSurface;
            this.viewAreaWidth = viewAreaWidth;
            this.viewAreaHeight = viewAreaHeight;

            imageAttributes = new ImageAttributes();
            imageAttributes.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255));

            screenGFX = drawingSurface.CreateGraphics();
            drawingSurface.SizeChanged += new EventHandler(drawingSurface_SizeChanged);
            drawingSurface.Paint +=new PaintEventHandler(frameTick_Tick);
            offscreenBitmap = new Bitmap(viewAreaWidth, viewAreaHeight);
            offscreenGFX = Graphics.FromImage(offscreenBitmap);

            frameTick = new Timer();
            frameTick.Interval = 40;
            frameTick.Tick += new EventHandler(frameTick_Tick);
            frameTick.Start();
        }
Example #23
0
        /// <summary>
        /// Instanciates a new background.
        /// </summary>
        /// <param name="map">The map to draw for the level.</param>
        /// <param name="backgroundElements">The backgroundelements to draw for the level.</param>
        public Background(string[] map, BackgroundElement[] backgroundElements)
        {
            int spriteWidth = 32;
            y = (map.Length * spriteWidth) - GameForm.GameArea.Height;
            focusRectangle = new Rectangle(0, map.Length * spriteWidth, GameForm.GameArea.Width, GameForm.GameArea.Height);
            Height = focusRectangle.Y - GameForm.GameArea.Height;
            background = new Bitmap(GameForm.GameArea.Width, map.Length * spriteWidth);
            Graphics g = Graphics.FromImage(background);

            imgAttribs = new ImageAttributes();
            imgAttribs.SetColorKey(Color.FromArgb(0, 66, 173), Color.FromArgb(0, 66, 173));

            //Loop trough all map strings.
            for(int i = 0; i < map.Length; ++i)
            {
                //Create a char array of all map elements.
                char[] mapElements = map[i].ToCharArray();

                //Loop trough all chars in the map string.
                for(int j = 0; j < mapElements.Length; ++j)
                {
                    //Drawnig the map element to the map bitmap.
                    int index = SpriteList.Instance.GetTileIndex(mapElements[j]);
                    int n = SpriteList.Instance.Tiles.Length;
                    g.DrawImage(SpriteList.Instance.Tiles[index], j * spriteWidth, i * spriteWidth);
                }
            }

            //Loop trough all background elements.
            for(int i = 0; i < backgroundElements.Length; ++i)
            {
                BackgroundElement e = backgroundElements[i];

                //Draw the map element to the map bitmap.
                if(e.Width > 32)
                    g.DrawImage(SpriteList.Instance.BigBackgroundElements[e.SpriteIndex], new Rectangle(e.X, e.Y, e.Width, e.Height), 0, 0, e.Width, e.Height, GraphicsUnit.Pixel, imgAttribs);
            }

            //Dispose the graphics element used to draw the background.
            g.Dispose();
        }
Example #24
0
        //the panel that uses this class just has to pass the surface in which to draw stuff
        //(most Systems.Windows.Forms.Control objects will do; e.g. can be the Form itself, a Panel contained within the Form, etc)
        public GFXEngine(Control drawingSurface, bool autoUpdate, bool autoScalling)
        {
            this.drawingSurface = drawingSurface;

            if (autoUpdate)
            {
                if (autoScalling)
                {
                    this.drawingSurface.Paint += new PaintEventHandler(updateSurfaceHandlerWithScalling);
                }
                else
                {
                    this.drawingSurface.Paint += new PaintEventHandler(updateSurfaceHandler);
                }
            }

            g = this.drawingSurface.CreateGraphics();

            offScreenBmp = new Bitmap(this.drawingSurface.Width, drawingSurface.Height);
            offScreenDC = Graphics.FromImage(offScreenBmp);

            defaultBrush = new SolidBrush(Color.FromArgb(255, 255, 255));

            //use this to omit the transparent colour
            imageAttributes = new ImageAttributes();
            imageAttributes.SetColorKey(Color.FromArgb(Common.ALPHA_RED, Common.ALPHA_GREEN, Common.ALPHA_BLUE),
                Color.FromArgb(Common.ALPHA_RED, Common.ALPHA_GREEN, Common.ALPHA_BLUE));

            tileSet = new TileSet();

            mapOffsetX = 0;
            mapOffsetY = 0;

            animationTimer = new Timer();
            animationTimer.Interval = 10;
            animationTimer.Tick += new System.EventHandler(handleTileAnimations);
            animationTimer.Start();
        }
Example #25
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Image != null)
            {
                var destRect = new Rectangle(0, 0, Width, Height);
                var rect = new Rectangle(0, 0, Image.Width, Image.Height);

                if (SizeMode == PictureBoxSizeMode.CenterImage)
                {
                    destRect = new Rectangle((Width - Image.Width) / 2, (Height - Image.Height) / 2, Image.Width, Image.Height);
                }
                else if (SizeMode == PictureBoxSizeMode.Normal)
                {
                    destRect = new Rectangle(0, 0, Image.Width, Image.Height);
                }

                using (var imageAttr = new ImageAttributes())
                {
                    imageAttr.SetColorKey(TransparentColor, TransparentColor);
                    e.Graphics.DrawImage(Image, destRect, rect.X, rect.Y, rect.Width, rect.Height, GraphicsUnit.Pixel, imageAttr);
                }
            }
        }
Example #26
0
        public ShapeObject(LayerManager layerManager, String filePath)
        {
            this._layerType = LayerType.Shape;
            this.Description = "ESRI Shapedatei";
            this.Changed = this.Visible = true;

            this.layerManager = layerManager;
            this.LayerInfo = new LayerInfo(filePath);
            this.access = "rb";
            Color tempColor = layerManager.NewLayerStyle.NewColor;
            this.vectorInfo = new VectorInfo(tempColor,Color.White,new Pen(tempColor,1.0f));
            this.m_filePath = System.IO.Path.GetDirectoryName(filePath);
            this.m_fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);

            int i = filePath.LastIndexOf("\\");

            this.LayerName = filePath.Substring(i + 1,
                filePath.LastIndexOf(".") - i - 1);

            // new InmageAttributes
            imageAttributes = new ImageAttributes();
            imageAttributes.SetColorKey(Color.NavajoWhite, Color.NavajoWhite);
            bitmap = new Bitmap(1, 1, PixelFormat.Format16bppRgb555);
        }
        public Image GetName(int nameno, int scale)
        {
            Bitmap name;
            Bitmap scaled = new Bitmap(64 * scale, 16 * scale);

            System.Resources.ResourceManager resources = new System.Resources.ResourceManager("AtelierElieScripter.res.NameGFX", System.Reflection.Assembly.GetExecutingAssembly());

            name = (Bitmap)resources.GetObject("008_" + nameno.ToString("D3"));

            if (name != null)
            {
                Imaging.ImageAttributes attr = new Imaging.ImageAttributes();
                attr.SetColorKey(Color.Black, Color.Black);

                using (Graphics g = Graphics.FromImage(scaled))
                {
                    g.DrawImage(name, new Rectangle(0, 0, 64 * scale, 16 * scale), 0, 0, 64, 16, GraphicsUnit.Pixel, attr);
                }

            }

            return scaled;
        }
Example #28
0
			private Image CreateImage(Image value, Color transparentColor)
			{
				int imageWidth;
				int imageHeight;
				ImageAttributes imageAttributes;

				if (transparentColor.A == 0)
					imageAttributes = null;
				else {
					imageAttributes = new ImageAttributes();
					imageAttributes.SetColorKey (transparentColor, transparentColor);
				}

				var bitmap = new Bitmap (imageWidth = this.imageSize.Width, imageHeight = this.imageSize.Height, PixelFormat.Format32bppArgb);
				using (var graphics = Graphics.FromImage (bitmap))
					graphics.DrawImage (value, new Rectangle(0, 0, imageWidth, imageHeight), 0, 0, value.Width, value.Height, GraphicsUnit.Pixel, imageAttributes);

				if (imageAttributes != null)
					imageAttributes.Dispose ();

				ReduceColorDepth (bitmap);
				return bitmap;
			}
Example #29
0
			private int AddItemInternal(ImageListItem item)
			{
				if (Changed != null)
					Changed (this, EventArgs.Empty);

				if (item.Image is Icon) {
					int imageWidth;
					int imageHeight;
					Bitmap bitmap;
					Graphics graphics;

					bitmap = new Bitmap(imageWidth = this.imageSize.Width, imageHeight = this.imageSize.Height, PixelFormat.Format32bppArgb);
					graphics = Graphics.FromImage(bitmap);
					graphics.DrawIcon((Icon)item.Image, new Rectangle(0, 0, imageWidth, imageHeight));
					graphics.Dispose();

					ReduceColorDepth(bitmap);
					return list.Add(bitmap);
				}
				else if ((item.Flags & ItemFlags.ImageStrip) == 0)
					return list.Add(CreateImage((Image)item.Image, (item.Flags & ItemFlags.UseTransparentColor) == 0 ? this.transparentColor : item.TransparentColor));
				else {
					int imageX;
					int width;
					int imageWidth;
					int imageHeight;
					int index;
					Image image;
					Bitmap bitmap;
					Graphics graphics;
					Rectangle imageRect;
					ImageAttributes imageAttributes;

					// When ImageSize was changed after adding image strips
					// Count will return invalid values based on old ImageSize
					// but when creating handle either ArgumentException will
					// be thrown or image strip will be added according to the
					// new ImageSize. This can result in image count
					// difference that can result in exceptions in methods
					// that use Count before creating handle. In addition this
					// can result in the loss of sync with keys. When doing
					// the same after handle was created there are no problems
					// as handle will be recreated after changing ImageSize
					// that results in the loss of images added previously.

					if ((width = (image = (Image)item.Image).Width) == 0 || (width % (imageWidth = this.imageSize.Width)) != 0)
						throw new ArgumentException("Width of image strip must be a positive multiple of ImageSize.Width.", "value");

					if (image.Height != (imageHeight = this.imageSize.Height))
						throw new ArgumentException("Height of image strip must be equal to ImageSize.Height.", "value");

					imageRect = new Rectangle(0, 0, imageWidth, imageHeight);
					if (this.transparentColor.A == 0)
						imageAttributes = null;
					else {
						imageAttributes = new ImageAttributes();
						imageAttributes.SetColorKey(this.transparentColor, this.transparentColor);
					}

					index = list.Count;
					for (imageX = 0; imageX < width; imageX += imageWidth) {
						bitmap = new Bitmap(imageWidth, imageHeight, PixelFormat.Format32bppArgb);
						graphics = Graphics.FromImage(bitmap);
						graphics.DrawImage(image, imageRect, imageX, 0, imageWidth, imageHeight, GraphicsUnit.Pixel, imageAttributes);
						graphics.Dispose();

						ReduceColorDepth(bitmap);
						list.Add(bitmap);
					}

					if (imageAttributes != null)
						imageAttributes.Dispose();

					return index;
				}
			}
Example #30
0
 private static void MakeTransparent(string p)
 {
     FileStream fs = new FileStream(p, FileMode.Open, FileAccess.Read);
     MemoryStream ms = new MemoryStream();
     fs.CopyTo(ms);
     ms.Position = 0;
     fs.Close();
     using (Image original = new Bitmap(ms))
     {
         using (Bitmap image = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb))
         {
             Graphics g = Graphics.FromImage(image);
             ImageAttributes ia = new ImageAttributes();
             ia.SetColorKey(Color.FromArgb(0, 0xde, 0), Color.FromArgb(33, 255, 5));
             g.DrawImage(
                 original,
                 new Rectangle(0, 0, original.Width, original.Height),
                 0,
                 0,
                 original.Width,
                 original.Height,
                 GraphicsUnit.Pixel,
                 ia);
             image.Save(p, ImageFormat.Png);
             g.Dispose();
             ia.Dispose();
         }
     }
 }