当前位置: 首页>>代码示例>>C#>>正文


C# IGraphics.DrawImage方法代码示例

本文整理汇总了C#中IGraphics.DrawImage方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphics.DrawImage方法的具体用法?C# IGraphics.DrawImage怎么用?C# IGraphics.DrawImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGraphics的用法示例。


在下文中一共展示了IGraphics.DrawImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawString

        public void DrawString(IGraphics g, string text, Font font, Brush brush, PointF location)
        {
            int oldCount = _glyphCoords.Count;
            AddString(text, font, brush, g.TextRenderingHint);
            if (g is GLGraphics)
                UpdateTextureIfNeeded();

            List<RectangleF> glyphDst = new List<RectangleF>();
            List<Rectangle> glyphSrc = new List<Rectangle>();

            location.X += 2.0f; // magic ... really don't know how to get this offset from MeasureString

            foreach (var c in text)
            {
                var glyphCoord = _glyphCoords[c];

                var glyphSize = glyphCoord.RealSize;
                glyphSize.Width = (float)Math.Ceiling(glyphSize.Width);
                glyphSize.Height = (float)Math.Ceiling(glyphSize.Height);

                glyphDst.Add(new RectangleF(location, glyphSize));
                glyphSrc.Add(glyphCoord.GlyphRect);

                if (g is GDIGraphics)
                    g.DrawImage(_bitmap, location.X, location.Y, glyphCoord.GlyphRect.ToRectangleF(), GraphicsUnit.Pixel);

                location.X += (float)Math.Round(glyphCoord.RealSize.Width + 0.2f); // another magic
            }

            if (g is GLGraphics)
                _texture.DrawGlyphs(glyphDst, glyphSrc);
        }
开发者ID:filipkunc,项目名称:GLGraphics,代码行数:32,代码来源:GlyphTextureCache.cs

示例2: DrawBackgroundImage

        /// <summary>
        /// Draw the background image of the given box in the given rectangle.<br/>
        /// Handle background-repeat and background-position values.
        /// </summary>
        /// <param name="g">the device to draw into</param>
        /// <param name="box">the box to draw its background image</param>
        /// <param name="imageLoadHandler">the handler that loads image to draw</param>
        /// <param name="rectangle">the rectangle to draw image in</param>
        public static void DrawBackgroundImage(IGraphics g, CssBox box, ImageLoadHandler imageLoadHandler, RectangleF rectangle)
        {
            // image size depends if specific rectangle given in image loader
            var imgSize = new Size(imageLoadHandler.Rectangle == Rectangle.Empty ? imageLoadHandler.Image.Width : imageLoadHandler.Rectangle.Width,
                                   imageLoadHandler.Rectangle == Rectangle.Empty ? imageLoadHandler.Image.Height : imageLoadHandler.Rectangle.Height);

            // get the location by BackgroundPosition value
            var location = GetLocation(box.BackgroundPosition, rectangle, imgSize);

            var srcRect = imageLoadHandler.Rectangle == Rectangle.Empty
                              ? new Rectangle(0, 0, imgSize.Width, imgSize.Height)
                              : new Rectangle(imageLoadHandler.Rectangle.Left, imageLoadHandler.Rectangle.Top, imgSize.Width, imgSize.Height);

            // initial image destination rectangle
            var destRect = new Rectangle(location, imgSize);

            // need to clip so repeated image will be cut on rectangle
            var prevClip = g.GetClip();
            var lRectangle = rectangle;
            lRectangle.Intersect(prevClip);
            g.SetClip(lRectangle);

            switch( box.BackgroundRepeat )
            {
                case "no-repeat":
                    g.DrawImage(imageLoadHandler.Image, destRect, srcRect);
                    break;
                case "repeat-x":
                    DrawRepeatX(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
                    break;
                case "repeat-y":
                    DrawRepeatY(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
                    break;
                default:
                    DrawRepeat(g, imageLoadHandler, rectangle, srcRect, destRect, imgSize);
                    break;
            }

            g.SetClip(prevClip);
        }
开发者ID:havlenapetr,项目名称:HTMLRenderer,代码行数:48,代码来源:BackgroundImageDrawHandler.cs

示例3: PaintWithImage

 public void PaintWithImage(IGraphics g, AndroidImage image)
 {
     g.DrawImage (image, boundary.Left, boundary.Top, 0, 0, image.Width, image.Height);
 }
开发者ID:Paludan,项目名称:BeerRun,代码行数:4,代码来源:GameButton.cs

示例4: DrawStatus

 public void DrawStatus(IGraphics graphics)
 {
     graphics.SetColor(255, 128, 192, 255);
     graphics.DrawRectangle(480, 0, 160, 480);
     graphics.SetColor(255, 255, 255, 255);
     graphics.DrawImage(Image.Hud, FIELD_WIDTH + 16 + 2, 32 + 8 + 4, 128, 64, 2, 0);
     graphics.DrawImage(Image.Hud, FIELD_WIDTH + 16 - 2, 32 + 8 - 4, 128, 64, 1, 0);
     graphics.SetColor(255, 255, 255, 255);
     graphics.DrawString("TOP SCORE", (640 - FIELD_WIDTH - 9 * 16) / 2 + FIELD_WIDTH, 128 + 8);
     {
         string s = highScore.ToString();
         graphics.DrawString(s, (640 - FIELD_WIDTH - s.Length * 16) / 2 + FIELD_WIDTH, 160 + 8);
     }
     graphics.DrawString("SCORE", (640 - FIELD_WIDTH - 5 * 16) / 2 + FIELD_WIDTH, 208 + 8);
     {
         string s = score.ToString();
         graphics.DrawString(s, (640 - FIELD_WIDTH - s.Length * 16) / 2 + FIELD_WIDTH, 240 + 8);
     }
     graphics.DrawString("LEVEL", (640 - FIELD_WIDTH - 5 * 16) / 2 + FIELD_WIDTH, 288 + 8);
     {
         string s = Level.ToString();
         graphics.DrawString(s, (640 - FIELD_WIDTH - s.Length * 16) / 2 + FIELD_WIDTH, 320 + 8);
     }
     graphics.DrawString("LEFT", (640 - FIELD_WIDTH - 4 * 16) / 2 + FIELD_WIDTH, 368 + 8);
     {
         int drawX = (640 - FIELD_WIDTH - (left * 40 - 8)) / 2 + FIELD_WIDTH;
         for (int i = 0; i < left; i++)
         {
             graphics.DrawImage(Image.Player, drawX + i * 40, 400 + 8, 32, 32, 0, 0);
         }
     }
 }
开发者ID:sinshu,项目名称:dtf,代码行数:32,代码来源:Game.cs

示例5: drawUIRunning

 /// <summary>
 /// Draws the user interface when GameState is running.
 /// </summary>
 /// <param name="g">The green component.</param>
 private void drawUIRunning(IGraphics g)
 {
     IImage butImg = PictureManager.Pictures ["button"];
     g.DrawImage (butImg, 0, 285, 0, 0, 65, 65);
     g.DrawImage (butImg, 0, 350, 0, 65, 65, 65);
     g.DrawImage (butImg, 0, 415, 0, 130, 65, 65);
     g.DrawImage (butImg, 0, 0, 0, 195, 35, 35);
 }
开发者ID:Paludan,项目名称:BeerRun,代码行数:12,代码来源:GameScreen.cs

示例6: DrawItem

		private void DrawItem(IGraphics g, EnumValue value, Rectangle record, Style style)
		{
			Font font = GetFont(style);
			string memberString = value.ToString();
			itemBrush.Color = style.EnumItemColor;

			if (style.UseIcons)
			{
				Image icon = Properties.Resources.EnumItem;
				g.DrawImage(icon, record.X, record.Y);

				Rectangle textBounds = new Rectangle(
					record.X + IconSpacing, record.Y,
					record.Width - IconSpacing, record.Height);

				g.DrawString(memberString, font, itemBrush, textBounds, memberFormat);
			}
			else
			{
				g.DrawString(memberString, font, itemBrush, record, memberFormat);
			}
		}
开发者ID:gbaychev,项目名称:NClass,代码行数:22,代码来源:EnumShape.cs

示例7: DrawBody

        /// <summary>
        /// Draws the  body
        /// </summary>
        /// <param name="graphics">graphics</param>
        /// <param name="gameTime">game time</param>
        private void DrawBody(IGraphics graphics, GameTime gameTime)
        {
            switch (this.WalkDirection)
            {
                case Direction.Up:
                    this.spriteBody.PlayAnimation(this.walkUpAnimation);
                    break;
                case Direction.Left:
                    this.spriteBody.PlayAnimation(this.walkLeftAnimation);
                    break;
                case Direction.Down:
                    this.spriteBody.PlayAnimation(this.walkDownAnimation);
                    break;
                case Direction.Right:
                    this.spriteBody.PlayAnimation(this.walkRightAnimation);
                    break;
                case Direction.Still:
                    this.spriteBody.PlayAnimation(this.stillAnimation);
                    break;
                default:
                    throw new ApplicationException("Direction not supported!");
            }

            if (this.WalkDirection == Direction.Still)
            {
                int frame = this.CurrentHealth > 0 ? 0 : 1;
                this.spriteBody.DrawFrame(graphics, this.Position, frame);
            }
            else
            {
                this.spriteBody.Draw(gameTime, graphics, this.Position, false);
            }

            if (this.CurrentHealth > 0 && this.HasVest)
            {
                graphics.DrawImage(this.vest, (int)this.Position.X, (int)this.Position.Y, this.vest.Width, this.vest.Height);
            }
        }
开发者ID:jrusev,项目名称:Games,代码行数:43,代码来源:Enemy.cs

示例8: Render

        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(IGraphics g, Map map)
        {
            if (BaseLayer != null)
            {
                BaseLayer.Render(g, map);
            }
            
            var fds = new FeatureCollectionSet();
            var box = map.Envelope;
            ExecuteIntersectionQuery(box, fds);
            
            if (fds.Count == 0 || fds[0].Count == 0)
            {
                base.Render(g, map);
                return;
            }

            var zoomIndex = GetZoomIndex(map.Zoom);
            var dot = _bitmaps[zoomIndex];
            var opacity = _opacity[zoomIndex];

            using (var image = new Bitmap(map.Size.Width + dot.Width, map.Size.Height + dot.Height, PixelFormat.Format32bppArgb))
            {
                using (IGraphics gr = Graphics.FromImage(image).G())
                    gr.Clear(Color.White);

                DrawPoints(map, fds[0], dot, image);
                Colorize(image, HeatColorBlend, opacity);
                
                g.DrawImage(image, -dot.Width/2, -dot.Height/2);
            }
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:37,代码来源:HeatLayer.cs

示例9: Draw

        void Draw(IGraphics g, DrawingMode mode)
        {
            g.SmoothingMode = checkBoxAntialiasing.Checked ? SmoothingMode.HighQuality : SmoothingMode.None;
            g.Clear(Color.White);

            DrawMillimeterGridInPixels(g, tabControl1.SelectedTab.Controls[0].ClientRectangle);

            g.PageUnit = GraphicsUnit.Millimeter;

            var points = _noisePoints;

            DrawLines(g, points, mode);

            g.ResetTransform();

            var path = CreateRoundedRectanglePath(new RectangleF(10, 10, 100, 40), 10);

            g.FillPath(new SolidBrush(Color.FromArgb(120, Color.LightSlateGray)), path);
            g.DrawPath(new Pen(Color.LightSlateGray, 0.0f), path);

            g.FillPie(new SolidBrush(Color.FromArgb(120, Color.CadetBlue)), new Rectangle(30, 20, 100, 100), 45.0f, 90.0f);
            g.DrawPie(new Pen(Color.CadetBlue, 0.0f), new Rectangle(30, 20, 100, 100), 45.0f, 90.0f);

            //GLGraphics gl = g as GLGraphics;
            //if (gl != null)
            //    gl.FillTextBackground = gl.FillTextBackground_glReadPixels;

            g.PageUnit = GraphicsUnit.Pixel;
            RectangleF rect = new RectangleF(30.0f, 15.0f, _testImage.Width, _testImage.Height);
            g.DrawImage(_testImage, rect);
            g.DrawRectangle(Pens.Black, rect.X, rect.Y, rect.Width, rect.Height);

            g.PageUnit = GraphicsUnit.Millimeter;

            g.HintTextBackgroundAction((gdi, textLocation, textRect) =>
            {
                _millimeterGridBrush.ResetTransform();
                _millimeterGridBrush.TranslateTransform(-textLocation.X, -textLocation.Y);
                gdi.FillRectangle(_millimeterGridBrush, textRect);
            });

            g.DrawString("Testovací řetězec pro odzkoušení správné implementace IGraphics - metody DrawString.",
                new Font("Arial", 12.0f), Brushes.Black, new PointF(100.0f, 58.0f));
        }
开发者ID:filipkunc,项目名称:GLGraphics,代码行数:44,代码来源:Form1.cs

示例10: PaintImp

        /// <summary>
        /// Paints the fragment
        /// </summary>
        /// <param name="g">the device to draw to</param>
        protected override void PaintImp(IGraphics g)
        {
            // load image iff it is in visible rectangle
            if (_imageLoadHandler == null)
            {
                _imageLoadHandler = new ImageLoadHandler(OnLoadImageComplete);
                _imageLoadHandler.LoadImage(HtmlContainer, GetAttribute("src"), HtmlTag != null ? HtmlTag.Attributes : null);
            }

            var rect = CommonUtils.GetFirstValueOrDefault(Rectangles);
            PointF offset = HtmlContainer.ScrollOffset;
            rect.Offset(offset);

            var prevClip = RenderUtils.ClipGraphicsByOverflow(g, this);

            PaintBackground(g, rect, true, true);
            BordersDrawHandler.DrawBoxBorders(g, this, rect, true, true);

            RectangleF r = _imageWord.Rectangle;
            r.Offset(offset);
            r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom;
            r.Y += ActualBorderTopWidth + ActualPaddingTop;

            if (_imageWord.Image != null)
            {
                if (_imageWord.ImageRectangle == Rectangle.Empty)
                    g.DrawImage(_imageWord.Image, Rectangle.Round(r));
                else
                    g.DrawImage(_imageWord.Image, Rectangle.Round(r), _imageWord.ImageRectangle);

                if (_imageWord.Selected)
                {
                    g.FillRectangle(GetSelectionBackBrush(true), _imageWord.Left + offset.X, _imageWord.Top + offset.Y, _imageWord.Width+2, DomUtils.GetCssLineBoxByWord(_imageWord).LineHeight);
                }
            }
            else if (_imageLoadingComplete)
            {
                if (_imageLoadingComplete && r.Width > 19 && r.Height > 19)
                {
                    RenderUtils.DrawImageErrorIcon(g, r);
                }
            }
            else
            {
                RenderUtils.DrawImageLoadingIcon(g, r);
                if (r.Width > 19 && r.Height > 19)
                {
                    g.DrawRectangle(Pens.LightGray, r.X, r.Y, r.Width, r.Height);
                }
            }

            RenderUtils.ReturnClip(g, prevClip);
        }
开发者ID:havlenapetr,项目名称:HTMLRenderer,代码行数:57,代码来源:CssBoxImage.cs

示例11: Draw

 public void Draw(IGraphics graphics)
 {
     graphics.SetColor(255, 0, 0, 0);
     graphics.Fill();
     int c = ticks % 384;
     int r, g, b;
     if (c < 64)
     {
         r = 255;
         g = c * 4;
         b = 0;
     }
     else if (c < 128)
     {
         r = (63 - (c - 64)) * 4;
         g = 255;
         b = 0;
     }
     else if (c < 192)
     {
         r = 0;
         g = 255;
         b = (c - 128) * 4;
     }
     else if (c < 256)
     {
         r = 0;
         g = (63 - (c - 192)) * 4;
         b = 255;
     }
     else if (c < 320)
     {
         r = (c - 256) * 4;
         g = 0;
         b = 255;
     }
     else
     {
         r = 255;
         g = 0;
         b = (63 - (c - 320)) * 4;
     }
     graphics.SetColor(255, r, g, b);
     graphics.EnableAddBlend();
     for (int i = 0; i < 128; i++)
     {
         int w = (int)Math.Round(8 * Utility.Sin(i * 2 + ticks * 4));
         graphics.DrawImage(Image.Dtf, 64 + w, 96 + i, 512, 1, i, 0);
     }
     graphics.SetColor(255, 255, 255, 255);
     /*
     for (int i = 0; i < NUM_STARS / 4; i++)
     {
         graphics.DrawImage(Image.Star, starX[i] - 4, starY[i] - 4, 8, 8, 0, 0);
     }
     */
     for (int i = NUM_STARS / 4; i < NUM_STARS / 2; i++)
     {
         graphics.DrawImage(Image.Star, starX[i] - 4, starY[i] - 4, 8, 8, 0, 1);
     }
     graphics.SetColor(255, 128, 128, 128);
     for (int i = NUM_STARS / 2; i < NUM_STARS; i++)
     {
         graphics.DrawImage(Image.Star, starX[i] - 4, starY[i] - 4, 8, 8, 0, 1);
     }
     graphics.DisableAddBlend();
     if (startGame)
     {
         int a = startCount * 32;
         if (a > 255)
         {
             a = 255;
         }
         graphics.SetColor(a, 255, 255, 255);
         graphics.Fill();
     }
     else
     {
         if (ticks / 15 % 2 == 0)
         {
             graphics.SetColor(255, 255, 255, 255);
             graphics.DrawString("PRESS ANY BUTTON TO START", 120, 480 - 128 - 8);
         }
     }
 }
开发者ID:sinshu,项目名称:dtf,代码行数:85,代码来源:Title.cs

示例12: HandleMapNewTileAvaliable

        static void HandleMapNewTileAvaliable(Map map, IGraphics g, Envelope box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
        {

            try
            {
                PointF min_f = map.WorldToImage(box.Min());
                PointF max_f = map.WorldToImage(box.Max());

                double minx = Math.Round(min_f.X);
                double miny = Math.Round(min_f.Y);
                double maxx = Math.Round(max_f.X);
                double maxy = Math.Round(max_f.Y);
                Point min = new Point(
                    Convert.ToInt32(minx), 
                    Convert.ToInt32(miny));                
                Point max = new Point(
                    Convert.ToInt32(maxx), 
                    Convert.ToInt32(maxy));
                g.DrawImage(bm,
                    min.X, max.Y, max.X - min.X, min.Y - max.Y,
                    0, 0, sourceWidth, sourceHeight,
                    GraphicsUnitType.Pixel,
                    imageAttributes);

                // g.Dispose();

            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                //this can be a GDI+ Hell Exception...
            }

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:34,代码来源:TileAsyncLayer.cs

示例13: DrawChevron

        private void DrawChevron(IGraphics g)
        {
            Bitmap chevron = (Collapsed) ? Properties.Resources.Expand : Properties.Resources.Collapse;
            Point location = new Point(Right - MarginSize - chevronSize.Width, Top + MarginSize);

            g.DrawImage(chevron, location);
        }
开发者ID:BachelorEric,项目名称:ModelFirst,代码行数:7,代码来源:TypeShape.cs

示例14: Render

        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(IGraphics g, Map map)
        {
            if (map.Center == null)
                throw (new ApplicationException("Cannot render map. View center not specified"));

            if (_image == null)
                throw new Exception("Image not set");

            // Style enabled?
            bool doRender = Style.Enabled;

            // Valid for this zoom
            if (map.Zoom < Style.MinVisible || Style.MaxVisible < map.Zoom)
                doRender = false;

            // View to render
            Envelope mapView = map.Envelope;
            
            // Layer view
            Envelope lyrView = _envelope;

            // Get the view intersection
            Envelope vi = mapView.Intersection(lyrView);
            if (doRender && !vi.IsNull)
            {
                // Image part
// ReSharper disable InconsistentNaming
                Point imgLT = Clip(_worldFile.ToRaster(new Coordinate(vi.MinX, vi.MaxY)));
                Point imgRB = Clip(_worldFile.ToRaster(new Coordinate(vi.MaxX, vi.MinY)));
                Rectangle imgRect = new Rectangle(imgLT, PointDiff(imgLT, imgRB, 1));

                // Map Part
                Point mapLT = Point.Truncate(map.WorldToImage(new Coordinate(vi.MinX, vi.MaxY)));
                Point mapRB = Point.Ceiling(map.WorldToImage(new Coordinate(vi.MaxX, vi.MinY)));
                Rectangle mapRect = new Rectangle(mapLT, PointDiff(mapLT, mapRB, 1));
// ReSharper restore InconsistentNaming

                // Set the interpolation mode
                Interpolation tmpInterpolationMode = g.InterpolationMode;
                g.InterpolationMode = InterpolationMode;

                // Render the image
                using (ImageAttributes ia = new ImageAttributes())
                {
                    ia.SetColorMatrix(new ColorMatrix { Matrix44 = 1 - Transparency },
                        ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    g.DrawImage(_image, 
                        mapRect.X, mapRect.Y, mapRect.Width, mapRect.Height,
                        imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
                        GraphicsUnitType.Pixel, ia);
                }

                // reset the interpolation mode
                g.InterpolationMode = tmpInterpolationMode;

            }

            base.Render(g, map);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:65,代码来源:GdiImageLayer.cs

示例15: DrawFrame

        /// <summary>
        /// Draws a frame
        /// </summary>
        /// <param name="spriteBatch">A graphics</param>
        /// <param name="position">A position</param>
        /// <param name="frameIndex">A frame index</param>
        public void DrawFrame(IGraphics spriteBatch, PointF position, int frameIndex)
        {
            // Calculate the source rectangle of the current frame.
            Rectangle source = new Rectangle(frameIndex * AnimTexture.FrameWidth, 0, AnimTexture.FrameWidth, AnimTexture.FrameHeight);
            Rectangle location = new Rectangle((int)position.X, (int)position.Y, source.Width, source.Height);

            // Draw the current frame.
            spriteBatch.DrawImage(AnimTexture.Texture, location, source, GraphicsUnit.Pixel);
        }
开发者ID:jrusev,项目名称:Games,代码行数:15,代码来源:Animation.cs


注:本文中的IGraphics.DrawImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。