DrawImageUnscaled() public method

public DrawImageUnscaled ( Image image, Point point ) : void
image Image
point Point
return void
Beispiel #1
0
        private void btnfig_Click(object sender, EventArgs e)
        {
            int    a = 1;
            int    b = 0;
            int    c = 0;
            double x, y;
            int    orig_x = pn1.Width / 2;
            int    orig_y = pn1.Height / 2;

            //
            Bitmap pen = new Bitmap(1, 1);

            pen.SetPixel(0, 0, Color.Green);
            System.Drawing.Graphics g = pn1.CreateGraphics();

            //

            for (double i = 0; i <= 100; i += 0.01)
            {
                x = i;
                y = (a * (x * x)) + ((b * x) + c);
                g.DrawImageUnscaled(pen, orig_x + (int)x, orig_y - (int)y);
                g.DrawImageUnscaled(pen, orig_x - (int )x, orig_y - (int)y);
                if (y >= orig_y)
                {
                    break;
                }
            }
        }
        public override void OnRender(Graphics g)
        {
            #if !PocketPC
             if(!Bearing.HasValue)
             {
            g.DrawImageUnscaled(Resources.shadow50, LocalPosition.X, LocalPosition.Y);
             }
             g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

             if(Bearing.HasValue)
             {
            g.RotateTransform(Bearing.Value - Overlay.Control.Bearing);
            g.FillPolygon(Brushes.Lime, Arrow);
             }

             g.ResetTransform();

             if(!Bearing.HasValue)
             {
            g.DrawImageUnscaled(Resources.bigMarkerGreen, LocalPosition.X, LocalPosition.Y);
             }
            #else
            DrawImageUnscaled(g, Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            DrawImageUnscaled(g, Resources.marker, LocalPosition.X, LocalPosition.Y);
            #endif
        }
Beispiel #3
0
 public void Draw(Graphics e)
 {
     kolizija = new Bitmap(ozadje);
     e.Clear(Color.Black);
     e.DrawImageUnscaled(ozadje, 0, 0);
     e.DrawImageUnscaled(igralci, 0, 0);
 }
Beispiel #4
0
        public static void DrawBackgroundStyle(Graphics g, Point location, Size size, Background background)
        {
            // draw background color
            g.FillRectangle(
                new SolidBrush(System.Drawing.Color.FromKnownColor(background.Color)),
                location.X,
                location.Y,
                size.Width,
                size.Height);

            // draw background image
            if (background.Image != null)
            {
                Image bg = background.Image; // Image.FromFile(this.Background.Image);
                switch (background.Repeat)
                {
                    case BackgroundRepeat.Undefined:
                    case BackgroundRepeat.Tile:
                        for (int i = 0; i < size.Width / bg.Width; i++)
                            for (int j = 0; j < size.Height / bg.Height; j++)
                                g.DrawImageUnscaled(bg, location.X + i * bg.Width, location.Y + j * bg.Height);
                        break;
                    case BackgroundRepeat.Strech:
                        g.DrawImage(bg, location.X, location.Y, size.Width, size.Height);
                        break;
                    case BackgroundRepeat.Center:
                        int posX = location.X + size.Width / 2 - bg.Width / 2;
                        int posY = location.Y + size.Height / 2 - bg.Height / 2;
                        g.DrawImageUnscaled(bg, posX, posY);
                        break;
                    default:
                        break;
                }
            }
        }
Beispiel #5
0
        public void Draw(int i, int j, Graphics g)
        {
            if (this.Orientation == 1)
                triImage = Properties.Resources.t1;

            if (this.Orientation == 2)
                triImage = Properties.Resources.t2;

            if (this.Orientation == 3)
                triImage = Properties.Resources.t3;

            if (this.Orientation == 4)
                triImage = Properties.Resources.t4;

            if (this.Orientation == 5)
                triImage = Properties.Resources.yellow;

            if (this.Orientation == 6)
                triImage = Properties.Resources.red;

            if (this.Orientation == 0)
                triImage = Properties.Resources.cleared;

            if (triImage != null)
            {
                if (this.Orientation != 0)
                    g.DrawImageUnscaled(Properties.Resources.cleared, new Point(8 + 17 * i + i * triImage.Width, 6 + 17 * j + j * triImage.Height));

                g.DrawImageUnscaled(triImage, new Point(8 + 17 * i + i * triImage.Width, 6 + 17 * j + j * triImage.Height));
            }
        }
Beispiel #6
0
        private void ShowNotes(System.Drawing.Graphics g)
        {
            showNotes.Sort();
            showNotes.Reverse();

            g.DrawImageUnscaled(Properties.Resources.Clef, 10, (StafPanel.Height - Properties.Resources.Clef.Height) / 2);
            ShowKey(g);

            // p = 25 G2, 35 C3, 45 F4
            int a    = 0;
            int pMax = 45;
            int pMin = 25;
            int cx   = 0;

            foreach (int n in showNotes)
            {
                int p = GetNotePos(curKey, n);
                int y = bY - p * sY;
                int x = 100;

                ShowSign(g, x, y, n);

                if (p == a - 1)
                {
                    x += 7;
                    a  = 0;
                    if (p == 35)
                    {
                        cx = 8;
                    }
                }
                else
                {
                    a = p;
                }

                g.DrawImageUnscaled(bmpNote, x, y);

                pMin = Math.Min(pMin, p);
                pMax = Math.Max(pMax, p);
            }

            // Draw staff lines
            for (int p = pMin; p <= pMax; p++)
            {
                if (p % 2 == 0)
                {
                    continue;
                }

                int   y      = bY - p * sY + sY;
                int   x1     = 100 - 5;
                int   x2     = 100 + 8 + 5;
                Point point1 = new Point(x1, y);
                Point point2 = new Point(x2, y);
                g.DrawLine(blackPen, point1, point2);
            }
        }
        public override void OnRender(Graphics g)
        {
            if (shotBellowMinInterval)
                g.DrawImageUnscaled(localcache2, LocalPosition.X, LocalPosition.Y);
            else
                g.DrawImageUnscaled(localcache1, LocalPosition.X, LocalPosition.Y);

            if (drawfootprint || IsMouseOver)
            {
                Overlay.Control.UpdatePolygonLocalPosition(footprintpoly);
                footprintpoly.OnRender(g);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Shows houses or hotels.
 /// </summary>
 public override void ShowHouses(Graphics g, int numberOfHouses)
 {
     if(numberOfHouses == 5)
     {
         g.DrawImageUnscaled(HotelVertical, Left, Top + 6);
     }
     else if(numberOfHouses >= 1 && numberOfHouses <= 4)
     {
         for (int i = 0; i < numberOfHouses; ++i)
         {
             g.DrawImageUnscaled(HouseVertical, Left, Bottom - i * 10 - 13);
         }
     }
 }
 /*
 * @param graphics
 */
 public override void draw(Graphics graphics)
 {
     if (turnRight)
     {
         // this is just a sample draw routine.  It needs to be overrided by the child object
         Bitmap bitmap = elements[((int)getTicks() * speed % (360 / TURN_ANGLE))];
         graphics.DrawImageUnscaled(bitmap, getX(), getY(), bitmap.Width, bitmap.Height);
     }
     else
     {
         // this is just a sample draw routine.  It needs to be overrided by the child object
         Bitmap bitmap = elements[((360 / TURN_ANGLE) - ((int)getTicks() * speed % (360 / TURN_ANGLE)) - 1)];
         graphics.DrawImageUnscaled(bitmap, getX(), getY(), bitmap.Width, bitmap.Height);
     }
 }
		public override void CopyBackBufferToScreen(Graphics displayGraphics)
		{
			WidgetForWindowsFormsBitmap aggBitmapAppWidget = ((WidgetForWindowsFormsBitmap)aggAppWidget);

			RectangleInt intRect = new RectangleInt(0, 0, (int)aggAppWidget.Width, (int)aggAppWidget.Height);
			aggBitmapAppWidget.bitmapBackBuffer.UpdateHardwareSurface(intRect);

			if (OsInformation.OperatingSystem != OSType.Windows)
			{
				//displayGraphics.DrawImage(aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap, windowsRect, windowsRect, GraphicsUnit.Pixel);  // around 250 ms for full screen
				displayGraphics.DrawImageUnscaled(aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap, 0, 0); // around 200 ms for full screnn
			}
			else
			{
				// or the code below which calls BitBlt directly running at 17 ms for full screnn.
				const int SRCCOPY = 0xcc0020;

				using (Graphics bitmapGraphics = Graphics.FromImage(aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap))
				{
					IntPtr displayHDC = displayGraphics.GetHdc();
					IntPtr bitmapHDC = bitmapGraphics.GetHdc();

					IntPtr hBitmap = aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap.GetHbitmap();
					IntPtr hOldObject = SelectObject(bitmapHDC, hBitmap);

					int result = BitBlt(displayHDC, 0, 0, aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap.Width, aggBitmapAppWidget.bitmapBackBuffer.windowsBitmap.Height, bitmapHDC, 0, 0, SRCCOPY);

					SelectObject(bitmapHDC, hOldObject);
					DeleteObject(hBitmap);

					bitmapGraphics.ReleaseHdc(bitmapHDC);
					displayGraphics.ReleaseHdc(displayHDC);
				}
			}
		}
Beispiel #11
0
        public void DrawFormBackgroud(Graphics g, Rectangle r)
        {
            drawing = new Bitmap(this.Width, AnimSize, g);
            gg = Graphics.FromImage(drawing);

            Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
            Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, AnimSize-9);
            LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 61), Color.FromArgb(47, colorR, colorR), LinearGradientMode.Vertical);
            //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
            LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
            //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
            ColorBlend blend = new ColorBlend();

            // Set multi-color gradient
            blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 0.95f,1f };
            blend.Colors = new[] { Color.FromArgb(47, colorR, colorR), Color.FromArgb(64, colorR + 22, colorR + 32), Color.FromArgb(66, colorR + 20, colorR + 35), Color.FromArgb(64, colorR + 20, colorR + 32), Color.FromArgb(49, colorR, colorR + 1), SystemColors.Control };
            //blend.Colors = new[] { Color.FromArgb(47, colorR, 64), Color.FromArgb(64, colorR + 32, 88), Color.FromArgb(66, colorR + 35, 90), Color.FromArgb(64, colorR + 32, 88), Color.FromArgb(49, colorR + 1, 66),SystemColors.Control };
            grad.InterpolationColors = blend;
            Font myf = new System.Drawing.Font(this.Font.FontFamily, 16);
            // Draw basic gradient and shadow
            //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gg.FillRectangle(grad, gradRect);
            gg.FillRectangle(shadow, shadowRect);
            gg.TextRenderingHint = TextRenderingHint.AntiAlias;
            gg.DrawString("Поиск по ресурсам сети", myf, Brushes.GhostWhite, new PointF(55, 15));
            gg.DrawImage(Properties.Resources.search1.ToBitmap(), 10, 10,32,32);

            g.DrawImageUnscaled(drawing, 0, 0);
            gg.Dispose();

            // Draw checkers
            //g.FillRectangle(checkers, r);
        }
Beispiel #12
0
        public Bitmap GetImage(Point offset, Size separation)
        {
            if (this._tiles == null)
            {
                return((Bitmap)null);
            }
            Bitmap bitmap = new Bitmap(this.TilesetWidth + separation.Width * this._cols + offset.X, this.TilesetHeight + separation.Height * this._rows + offset.Y, PixelFormat.Format32bppArgb);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage((Image)bitmap);
            int       index1 = 0;
            int       width  = this._max.Width;
            int       num1   = this._rows <= this._max.Height ? this._rows : this._max.Height;
            Rectangle empty  = Rectangle.Empty;
            Point     point  = Point.Empty;

            for (int index2 = 0; index2 < num1; ++index2)
            {
                for (int index3 = 0; index3 < width; ++index3)
                {
                    point = new Point(index3 * this.SnapSize.Width, index2 * this.SnapSize.Height);
                    int       num2      = index3 * separation.Width + offset.X;
                    int       num3      = index2 * separation.Height + offset.Y;
                    Rectangle rectangle = new Rectangle(point.X + index3 * separation.Width, point.Y + index2 * separation.Height, this.SnapSize.Width + separation.Width, this.SnapSize.Height + separation.Height);
                    if (index1 < this._tiles.Count && this._tiles[index1] != null)
                    {
                        graphics.DrawImageUnscaled((Image)this._tiles[index1], point.X + num2, point.Y + num3);
                    }
                    ++index1;
                }
            }
            return(bitmap);
        }
Beispiel #13
0
        private void DrawTiles(System.Drawing.Graphics gfx)
        {
            int   index1 = 0;
            int   width  = this._max.Width;
            int   num    = this._rows <= this._max.Height ? this._rows : this._max.Height;
            Point empty  = Point.Empty;

            for (int index2 = 0; index2 < num; ++index2)
            {
                for (int index3 = 0; index3 < width; ++index3)
                {
                    if (index1 < this._tiles.Count && this._tiles[index1] != null)
                    {
                        gfx.DrawImageUnscaled((Image)this._tiles[index1], index3 * this.SnapSize.Width, index2 * this.SnapSize.Height);
                    }
                    empty.X = index3 * this.SnapSize.Width;
                    empty.Y = index2 * this.SnapSize.Height;
                    gfx.DrawString(this._tiles[index1].Tag.ToString(), this.Font, Brushes.Black, (float)(empty.X - 1), (float)empty.Y);
                    gfx.DrawString(this._tiles[index1].Tag.ToString(), this.Font, Brushes.Black, (float)empty.X, (float)(empty.Y - 1));
                    gfx.DrawString(this._tiles[index1].Tag.ToString(), this.Font, Brushes.Black, (float)(empty.X + 1), (float)empty.Y);
                    gfx.DrawString(this._tiles[index1].Tag.ToString(), this.Font, Brushes.Black, (float)empty.X, (float)(empty.Y + 1));
                    gfx.DrawString(this._tiles[index1].Tag.ToString(), this.Font, Brushes.Yellow, (PointF)empty);
                    ++index1;
                }
            }
        }
Beispiel #14
0
        public void DrawBitmapInto(Graphics g, Point TLPoint, Size ViewPortSize, int squareS, bool isBichrom, bool forcePrecomputing = false)
        {
            // squareSize has changed OR no map has been loaded so far
            if (cachedBitmap == null ||
                squareSize != squareS ||
                cachedBitmapTLPoint.X > TLPoint.X || cachedBitmapTLPoint.Y > TLPoint.Y ||
                (cachedBitmapTLPoint.X + cachedBitmap.Width < getMapPixelSize().Width &&
                 cachedBitmapTLPoint.X + cachedBitmap.Width < TLPoint.X + ViewPortSize.Width) ||
                (cachedBitmapTLPoint.Y + cachedBitmap.Height < getMapPixelSize().Height &&
                 cachedBitmapTLPoint.Y + cachedBitmap.Height < TLPoint.Y + ViewPortSize.Height) ||
                isBichrom != isBichromatic ||
                forcePrecomputing
            )
            {
                //System.Windows.Forms.MessageBox.Show("cachedBitmap == null");
                squareSize = squareS;
                isBichromatic = isBichrom;
                PrecomputeBitmap(TLPoint, ViewPortSize);
            }

            // Draw it on the buffered bitmap
            bufferedBitmapGraphics.Clear(Color.White);
            Point relativeTLPoint = new Point(cachedBitmapTLPoint.X - TLPoint.X, cachedBitmapTLPoint.Y - TLPoint.Y);
            Rectangle rect = new Rectangle(relativeTLPoint, ViewPortSize);
            bufferedBitmapGraphics.DrawImageUnscaled(cachedBitmap, rect);

            g.DrawImageUnscaled(bufferedBitmap, 0, 0);
        }
Beispiel #15
0
 public void Draw(Graphics g, int animationCell, bool gameOver)
 {
     g.FillRectangle(Brushes.Black, boundaries);
     stars.Draw(g);
     playerShip.Draw(g);
     foreach (Invader invader in invaders)
         invader.Draw(g, animationCell);
     foreach (Shot shot in playerShots)
         shot.Draw(g);
     foreach (Shot shot in invaderShots)
         shot.Draw(g);
     using (Font font = new Font("Arial", 24, FontStyle.Bold))
         g.DrawString(score.ToString(), font, Brushes.Red, boundaries.X + 20, boundaries.Y + 20);
     g.DrawImageUnscaled(Properties.Resources.player,
             new Point(boundaries.Right - 110, boundaries.Top + 10));
     using (Font font = new Font("Arial", 20))
         g.DrawString("X " + livesLeft, font, Brushes.Yellow, boundaries.Right - 50, boundaries.Top + 10);
     if (gameOver)
     {
         using (Font font = new Font("Arial", 40))
             g.DrawString("Game Over", font, Brushes.Purple,
                 (boundaries.Width / 3), boundaries.Height / 3);
         using (Font font = new Font("Arial", 20))
             g.DrawString("Press 'Q' to quit\nor 'S' to restart", font, Brushes.Purple,
                 boundaries.Width / 3 + 45, boundaries.Height / 3 + 50);
     }
 }
        /// <summary>
        /// On draw on backbuffer
        /// </summary>
        protected override void OnDrawOnBackbuffer(ref System.Drawing.Graphics gfx)
        {
            // If layer is empty or background is empty, return
            if (_layer == null || App.Room.Backgrounds[0] == null || App.Room.Backgrounds[0].Image == null)
            {
                return;
            }

            // Draw layer
            gfx.DrawImageUnscaled(_layer.GetLayerImage(App.Room.Backgrounds[0], App.Room.Backgrounds[0].GetCondensedTileset(), .5f), Point.Empty);

            // Convert tile ids to optimized binary tiles and reset the tile count
            ExportTile[] tiles = _layer.GetExportTiles(App.Room.Backgrounds[0], false, -1);
            _tileCount = 0;

            // If there are rectangles to draw, draw them
            if (tiles != null || tiles.Length > 0)
            {
                // Create a list of rectangles
                List <Rectangle> rects = new List <Rectangle>();

                // Iterate through tiles
                foreach (ExportTile tile in tiles)
                {
                    rects.Add(tile.Rect);
                }

                // Draw rectangles and set tile count
                gfx.DrawRectangles(Pens.Red, rects.ToArray());
                _tileCount = rects.Count;
            }
        }
Beispiel #17
0
		public override void Render(Graphics graphics, IRender render)
		{
			byte opacity = 100;
			if (Table != null) opacity = Table.Opacity;

			//Draw indent
			SolidBrush brush = new SolidBrush(render.AdjustColor(Backcolor,1,opacity));
			brush.Color = Color.FromArgb(brush.Color.A /2, brush.Color);
			graphics.FillRectangle(brush,0,Rectangle.Top,Indent,Rectangle.Height);

			//Draw image
			float imageWidth = 0;
			if (Image != null)
			{
				System.Drawing.Image bitmap = Image.Bitmap;

				//Work out position of image
				float imageTop = (Rectangle.Height - bitmap.Height) / 2;
				if (imageTop < 0) imageTop = 0;
				
				imageWidth = bitmap.Width;
				graphics.DrawImageUnscaled(bitmap,Convert.ToInt32(Indent),Convert.ToInt32(Rectangle.Top+imageTop));
			}

			//Draw text
			RectangleF textRectangle = new RectangleF(Indent+imageWidth+4,Rectangle.Top,Rectangle.Width - Indent -4,Rectangle.Height);
			brush = new SolidBrush(render.AdjustColor(Forecolor,1,opacity));
			StringFormat format = new StringFormat();
			format.LineAlignment = StringAlignment.Center;
			format.FormatFlags = StringFormatFlags.NoWrap;
			graphics.DrawString(Text,Component.Instance.GetFont(FontName,FontSize,FontStyle),brush,textRectangle,format);
		}
Beispiel #18
0
        public static Image ConstructImageFromTileList(int TileXCount, int TileYCount, int scale, List <Bitmap> tileList)
        {
            Bitmap drawnX = new Bitmap(TileXCount * 8, TileYCount * 8);

            System.Drawing.Graphics gx = System.Drawing.Graphics.FromImage(drawnX);
            gx.Clear(Color.DeepPink);
            for (int i = 0; i < TileXCount * TileYCount; i++)
            {
                int hOff = (i % TileXCount) * 8;
                int vOff = ((i - (i % TileXCount)) / TileXCount) * 8;
                if (i < tileList.Count)
                {
                    gx.DrawImageUnscaled(tileList[i], hOff, vOff);
                }
            }
            if (scale > 1)
            {
                Bitmap scaledft           = new Bitmap(drawnX.Width * scale, drawnX.Height * scale);
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(scaledft);
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                g.DrawImage(drawnX, 0, 0, scaledft.Width, scaledft.Height);
                return(scaledft);
            }
            else
            {
                return(drawnX);
            }
        }
Beispiel #19
0
        public void DrawFormBackgroud(Graphics g, Rectangle r)
        {
            drawing = new Bitmap(this.Width, this.Height, g);
            gg = Graphics.FromImage(drawing);

            Rectangle shadowRect = new Rectangle(r.X, r.Y, r.Width, 10);
            Rectangle gradRect = new Rectangle(r.X, r.Y + 9, r.Width, 42);
            //LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 41, 61), Color.FromArgb(47, 64, 94), LinearGradientMode.Vertical);
            LinearGradientBrush shadow = new LinearGradientBrush(shadowRect, Color.FromArgb(30, 61, 41), Color.FromArgb(47, colorR, 64), LinearGradientMode.Vertical);
            //LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.FromArgb(47, 64, 94), Color.FromArgb(49, 66, 95), LinearGradientMode.Vertical);
            LinearGradientBrush grad = new LinearGradientBrush(gradRect, Color.Green, Color.DarkGreen, LinearGradientMode.Vertical);
            ColorBlend blend = new ColorBlend();

            // Set multi-color gradient
            blend.Positions = new[] { 0.0f, 0.35f, 0.5f, 0.65f, 1.0f };
            //blend.Colors = new[] { Color.FromArgb(47, 64, 94), Color.FromArgb(64, 88, 126), Color.FromArgb(66, 90, 129), Color.FromArgb(64, 88, 126), Color.FromArgb(49, 66, 95) };
            blend.Colors = new[] { Color.FromArgb(47,colorR, 64), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(66, colorR+35, 90), Color.FromArgb(64, colorR+32, 88), Color.FromArgb(49, colorR+1, 66) };
            grad.InterpolationColors = blend;
            Font myf=new System.Drawing.Font(this.Font.FontFamily,16);
            // Draw basic gradient and shadow
            //gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            gg.FillRectangle(grad, gradRect);
            gg.FillRectangle(shadow, shadowRect);
            gg.DrawString("Добавить один ПК", myf, Brushes.GhostWhite, new PointF(55, 15));
            gg.DrawImage(Properties.Resources.singleAdd1.ToBitmap(), 10, 10,32,32);

            g.DrawImageUnscaled(drawing, 0, 0);
            gg.Dispose();

            // Draw checkers
            //g.FillRectangle(checkers, r);
        }
Beispiel #20
0
        private static void ProcessLabelItem(LabelItem labelItem, Graphics g, PrintLabelSettings settings)
        {
            switch (labelItem.LabelType)
            {
                case LabelTypesEnum.Label:
                    g.DrawString(labelItem.LabelText,
                        new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
                        Brushes.Black, labelItem.StartX, labelItem.StartY);
                    break;
                case LabelTypesEnum.BarCode:
                    var content = labelItem.LabelText;

                    var writer = new BarcodeWriter
                    {
                        Format = BarcodeFormat.CODE_128,
                        Options = new ZXing.QrCode.QrCodeEncodingOptions
                        {
                            ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
                            Width = settings.BarCodeMaxWidth,
                            Height = settings.BarCodeHeight,
                            PureBarcode = true,
                        }
                    };
                    var barCodeBmp = writer.Write(content);
                    g.DrawImageUnscaled(barCodeBmp, labelItem.StartX, labelItem.StartY);
                    break;
                case LabelTypesEnum.Stamp:
                    var pen = new Pen(Color.Black, 2);
                    g.DrawEllipse(pen, labelItem.StartX, labelItem.StartY, settings.StampDiameter, settings.StampDiameter);
                    g.DrawString(labelItem.LabelText,
                        new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
                        Brushes.Black, labelItem.StartX + 2, labelItem.StartY + 11);
                    break;
            }
        }
Beispiel #21
0
        public override void CreateFromBitmap(Bitmap a_bmp)
        {
            if (m_tx != null)
            {
                m_tx.Dispose();
            }


            if (true)
            {
                m_tx = new Texture(this._device, a_bmp, Usage.None, Pool.Managed); //TODO: why is this so slow sometimes?
            }
            else
            {
                Endogine.BitmapHelpers.Canvas canvasX = Endogine.BitmapHelpers.Canvas.Create(a_bmp);
                PixelDataProvider             pdp     = new PixelDataProvider(a_bmp.Width, a_bmp.Height, canvasX.BitsPerPixel / 8, this._device, Usage.None);

                Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(pdp);
                System.Drawing.Graphics       g      = canvas.GetGraphics();
                g.DrawImageUnscaled(a_bmp, new Point(0, 0));
                //for (int y = canvas.Height-1; y >= 0; y--)
                //{
                //    for (int x = canvas.Width - 1; x >= 0; x--)
                //    {
                //        canvas.SetPixel
                //    }
                //}
                canvas.Locked = false;

                m_tx = pdp.Texture;
            }
        }
Beispiel #22
0
        public void DrawString(string text, Graphics graphics, int x, int y,
            int? maxWidth = null, int extraGap = 0)
        {
            int lineGap = baseLineGap + extraGap;
            foreach (char ch in text) {
                if (ch == '\r')
                    continue;

                // If a new line char, go to next line.
                if (ch == '\n') {
                    x = 0;
                    y += lineGap;
                    continue;
                }

                // Get glyph, if not found, take the deafault char.
                var glyph = font.SearchGlyphByChar(ch) ?? defaultChar;

                // If we are over the max width, go to next line.
                if (maxWidth.HasValue && x + glyph.Width.Advance > maxWidth) {
                    x = 0;
                    y += lineGap;
                }

                x += glyph.Width.BearingX;
                graphics.DrawImageUnscaled(glyph.ToImage(1, true), x, y);
                x += glyph.Width.Advance - glyph.Width.BearingX;
            }
        }
        /// <summary>
        /// Draws all the tiles
        /// </summary>
        private void DrawTiles(System.Drawing.Graphics gfx)
        {
            // Tile indexer
            int   index = 0;
            int   cols  = _max.Width;
            int   rows  = _rows <= _max.Height ? _rows : _max.Height;
            Point id    = Point.Empty;

            // Iterate through rows
            for (int row = 0; row < rows; row++)
            {
                // Iterate through columns
                for (int col = 0; col < cols; col++)
                {
                    // If the tile is within bounds, and is not empty, draw tile
                    if (index < _tiles.Count && _tiles[index] != null)
                    {
                        gfx.DrawImageUnscaled(_tiles[index], (col * SnapSize.Width), (row * SnapSize.Height));
                    }

                    id.X = col * SnapSize.Width;
                    id.Y = row * SnapSize.Height;

                    // Draw tile ids
                    gfx.DrawString(_tiles[index].Tag.ToString(), Font, Brushes.Black, id.X - 1, id.Y);
                    gfx.DrawString(_tiles[index].Tag.ToString(), Font, Brushes.Black, id.X, id.Y - 1);
                    gfx.DrawString(_tiles[index].Tag.ToString(), Font, Brushes.Black, id.X + 1, id.Y);
                    gfx.DrawString(_tiles[index].Tag.ToString(), Font, Brushes.Black, id.X, id.Y + 1);
                    gfx.DrawString(_tiles[index].Tag.ToString(), Font, Brushes.Yellow, id);

                    // Increment the indexer
                    index++;
                }
            }
        }
        private void DrawControllerToggle(System.Drawing.Graphics graphics, PointF point, bool enabled)
        {
            var labelRectangle = MeasureString(graphics, ControllerToggleText, _labelsTextFont);

            // Use relative positions so we can center the the entire drawing later.

            float keyWidth  = _keyModeIcon.Width;
            float keyHeight = _keyModeIcon.Height;

            float labelPositionX = keyWidth + 8 - labelRectangle.X;
            float labelPositionY = -labelRectangle.Y - 1;

            float keyX = 0;
            float keyY = (int)((labelPositionY + labelRectangle.Height - keyHeight) / 2);

            float fullWidth  = labelPositionX + labelRectangle.Width;
            float fullHeight = Math.Max(labelPositionY + labelRectangle.Height, keyHeight);

            // Convert all relative positions into absolute.

            float originX = (int)(point.X - fullWidth / 2);
            float originY = (int)(point.Y - fullHeight / 2);

            keyX += originX;
            keyY += originY;

            var labelPosition   = new PointF(labelPositionX + originX, labelPositionY + originY);
            var overlayPosition = new Point((int)keyX, (int)keyY);

            graphics.DrawImageUnscaled(_keyModeIcon, overlayPosition);

            DrawString(graphics, ControllerToggleText, _labelsTextFont, _textNormalBrush, labelPosition);
        }
Beispiel #25
0
        internal void RefreshInRect(Graphics eg, Rectangle rect) {

            if (!gbRefresh) return;

            Random rnd = new Random();

            if (rect.Width <= 0 || rect.Height <= 0) return;

            //using (Graphics eg = base.CreateGraphics()) {
            using (Bitmap Bmp = new Bitmap(rect.Width, rect.Height)) {
                using (Graphics g = Graphics.FromImage(Bmp)) {
                    g.Clear(Color.White);

                    //发送绘制消息
                    PaintMessage m = new PaintMessage(g, rect);
                    gManager.SendMessage(m);
                }

                if (eg != null) {
                    eg.DrawImageUnscaled(Bmp, rect.X, rect.Y);
                } else {
                    try {
                        using (Graphics g = this.CreateGraphics()) {
                            g.DrawImageUnscaled(Bmp, rect.X, rect.Y);
                            //System.Diagnostics.Debug.WriteLine("GPanel\\>RefreshInRect" + rect.ToString());
                        }
                    } catch { }
                }

            }
        }
            /// <summary>
            /// Draws the current state of the track bar to the specified graphics context with a given alpha level.
            /// </summary>
            public void DrawTrackBar(System.Drawing.Graphics g, int alpha)
            {
                // if the alpha value is 0, we don't need to draw anything!
                if (alpha <= 0)
                {
                    return;
                }

                Bitmap source = this.Buffer;

                if (alpha >= 255)
                {
                    // if the alpha value is 255, skip the secondary buffer since the primary buffer has exactly what we need!
                    g.DrawImageUnscaled(source, _clientBounds.Location);
                }
                else
                {
                    Bitmap    buffer    = new Bitmap(source.Width, source.Height, PixelFormat.Format32bppArgb);
                    Rectangle rectangle = new Rectangle(Point.Empty, source.Size);

                    BitmapData sourceData = source.LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    BitmapData bufferData = buffer.LockBits(rectangle, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                    try
                    {
                        unsafe
                        {
                            float sAlpha          = alpha / 255f;
                            int   length          = sourceData.Height * sourceData.Stride / 4;
                            int * sourceDataArray = (int *)sourceData.Scan0.ToPointer();
                            int * bufferDataArray = (int *)bufferData.Scan0.ToPointer();
                            for (int n = 0; n < length; ++n)
                            {
                                int value = *(sourceDataArray++);
                                *(bufferDataArray++) = (value & 0x00FFFFFF) | ((byte)(((value >> 24) & 0x0FF) * sAlpha) << 24);
                            }
                        }
                    }
                    finally
                    {
                        source.UnlockBits(sourceData);
                        buffer.UnlockBits(bufferData);
                    }

                    g.DrawImageUnscaled(buffer, _clientBounds.Location);
                }
            }
 public void PaintHive(Graphics g)
 {
     g.FillRectangle(Brushes.SkyBlue, _hiveForm.ClientRectangle);
     g.DrawImageUnscaled(_hiveInside, 0, 0);
     foreach (Bee bee in _world.Bees)
         if (!bee.IsInsideHive)
             g.DrawImageUnscaled(_beeAnimationLarge[_cell], bee.Location.X, bee.Location.Y);
 }
Beispiel #28
0
 public void Draw(Graphics g, Point center, Color color)
 {
     g.DrawImageUnscaled(
         this.Bitmap,
         center.X - this.Bitmap.Width / 2,
         center.Y - this.Bitmap.Height / 2
     );
 }
Beispiel #29
0
 public override void OnRender(Graphics g)
 {
     Matrix temp = g.Transform;
     g.TranslateTransform(LocalPosition.X, LocalPosition.Y);
     Image pic = global::MultiWiiWinGUI.Properties.Resources.home;
     g.DrawImageUnscaled(pic, pic.Width / -2 - 7, -pic.Height-14);
     g.Transform = temp;
 }
Beispiel #30
0
        /// <summary>
        /// 按宽X长比例切图 并补白
        /// </summary>
        /// <param name="imagePath">源图地址</param>
        /// <param name="savePath">新图地址</param>
        /// <param name="newWidth">宽度</param>
        /// <param name="newHeight">高度</param>
        /// <param name="error">出错时执行</param>
        /// <param name="bgcolor">填充背景色</param>
        /// <returns>成功true失败false</returns>
        public static bool CutImageByWidthHeight(string imagePath, string savePath, int newWidth, int newHeight, Color bgcolor, Action <Exception> error = null)
        {
            //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(imagePath);
            int  ow       = originalImage.Width;  //原始宽度
            int  oh       = originalImage.Height; //原始高度
            Size toSize   = ResizeSite(new Size(newWidth, newHeight), new Size(ow, oh));
            int  towidth  = toSize.Width;         //原图片缩放后的宽度
            int  toheight = toSize.Height;        //原图片缩放后的高度
            int  x        = 0;
            int  y        = 0;

            x = (newWidth - towidth) / 2;
            y = (newHeight - toheight) / 2;
            //新建一个bmp图片
            System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
            //新建一个画板
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //清空画布并以透明背景色填充
            g.Clear(bgcolor);
            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
                        new System.Drawing.Rectangle(0, 0, ow, oh),
                        System.Drawing.GraphicsUnit.Pixel);
            //--------------------------------------------------------------------------------
            //新建一个bmp图片2
            System.Drawing.Image bitmap2 = new System.Drawing.Bitmap(newWidth, newHeight);
            //新建一个画板2
            System.Drawing.Graphics g2 = System.Drawing.Graphics.FromImage(bitmap2);
            //设置高质量插值法
            g2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //设置高质量,低速度呈现平滑程度
            g2.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //清空画布并以透明背景色填充
            g2.Clear(bgcolor);
            g2.DrawImageUnscaled(bitmap, new Point(x, y));

            try {
                bitmap2.Save(savePath, originalImage.RawFormat);
                return(true);
            } catch (System.Exception ex) {
                if (error.IsNotNull())
                {
                    error(ex);
                }
                return(false);
            } finally {
                originalImage.Dispose();
                bitmap.Dispose();
                bitmap2.Dispose();
                g2.Dispose();
                g.Dispose();
            }
        }
Beispiel #31
0
        public Wallpaper()
        {
            s = Settings.Instance;
            allScreen = MultiScreenInfo.Instance;
            CanAddAnotherBitmap = true;

            try
            {
                desktop = new Bitmap(allScreen.VirtualDesktop.Width, allScreen.VirtualDesktop.Height);
                gDesktop = Graphics.FromImage(desktop);
                gDesktop.SetHighQuality();
                needFullRedraw = true;

                try
                {
                    if (allScreen.IsChanged == false)
                    {
                        var currentPath = GetCurrentPath();
                        var expectedPath = SafeFilename.Convert(s.SaveFolder, "Current Wallpaper.bmp", true);

                        if (currentPath == expectedPath)
                        {
                            using (var currentDesktop = new Bitmap(currentPath))
                            {
                                //not needed?
                                if (currentDesktop.Size == allScreen.VirtualDesktop.Size)
                                {
                                    gDesktop.DrawImageUnscaled(currentDesktop, 0, 0);
                                    needFullRedraw = false;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            catch
            {
                if (gDesktop != null)
                {
                    gDesktop.Dispose();
                    gDesktop = null;
                }

                if (desktop != null)
                {
                    desktop.Dispose();
                    desktop = null;
                }
            }

            if (desktop == null)
            {
                throw new ArgumentException();
            }
        }
Beispiel #32
0
 public void Render(Graphics g)
 {
     if (isFirst)
     {
         RePaint();
         isFirst = false;
     }
     g.DrawImageUnscaled(_page.ImageBuffer, 0, 0);
 }
Beispiel #33
0
        public void DrawImageUnscaled(Image image, Rectangle rect)
        {
            Bitmap currentBitmap = new Bitmap(rect.Width, rect.Height);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(currentBitmap);
            g.DrawImageUnscaled(image, new Rectangle(0, 0, rect.Width, rect.Height));

            this.DrawImage(currentBitmap, rect);
        }
Beispiel #34
0
        public static void DrawLine(Graphics gr, Color color, int x1, int y1, int x2, int y2)
        {
            _pixelBitmap.SetPixel(0, 0, color);

            int pntx = x1;
            int pnty = y1;

            int f = 0;
            int fx;

            int dx = x2 - x1;
            int dy = y2 - y1;

            int sx = Math.Sign(dx);
            int sy = Math.Sign(dy);
            dx *= sx;
            dy *= sy;

            bool drawHoriz = false;
            if (Math.Abs(x2 - x1) > Math.Abs(y2 - y1))
            {
                drawHoriz = true;
            }

            while (true)
            {
                gr.DrawImageUnscaled(_pixelBitmap, pntx, pnty);

                if ((drawHoriz && pntx == x2)
                || (!drawHoriz && pnty == y2))
                    break;

                if (drawHoriz)
                {
                    fx = f + dy;
                    f = fx - dx;

                    pntx += sx;
                }
                else
                {
                    fx = f + dx;
                    f = fx - dy;

                    pnty += sy;
                }

                if (Math.Abs(fx) < Math.Abs(f))
                    f = fx;
                else
                    if (drawHoriz)
                        pnty += sy;
                    else
                        pntx += sx;
            } //while
        }
Beispiel #35
0
            /// <summary>
            /// Draws the current state of the track bar to the specified graphics context with a given alpha level.
            /// </summary>
            public void DrawTrackBar(System.Drawing.Graphics g, int alpha)
            {
                if (alpha >= 255)
                {
                    // if the alpha value is 255, skip the secondary buffer since the primary buffer has exactly what we need!
                    g.DrawImageUnscaled(this.Buffer, _clientBounds.Location);
                }
                else if (alpha > 0)
                {
                    // if the alpha value is 0, we don't need to draw anything!

                    Bitmap    source    = this.Buffer;
                    Bitmap    buffer    = new Bitmap(source.Width, source.Height, PixelFormat.Format32bppArgb);
                    Rectangle rectangle = new Rectangle(Point.Empty, source.Size);

                    BitmapData sourceData = source.LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    BitmapData bufferData = buffer.LockBits(rectangle, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                    try
                    {
                        unsafe
                        {
                            int   length          = sourceData.Height * sourceData.Stride;
                            byte *sourceDataArray = (byte *)sourceData.Scan0.ToPointer();
                            byte *bufferDataArray = (byte *)bufferData.Scan0.ToPointer();
                            for (int n = 0; n < length; n += 4)
                            {
                                bufferDataArray[n + 0] = sourceDataArray[n + 0];
                                bufferDataArray[n + 1] = sourceDataArray[n + 1];
                                bufferDataArray[n + 2] = sourceDataArray[n + 2];
                                bufferDataArray[n + 3] = (byte)(alpha * (sourceDataArray[n + 3] / 255f));
                            }
                        }
                    }
                    finally
                    {
                        source.UnlockBits(sourceData);
                        buffer.UnlockBits(bufferData);
                    }

                    g.DrawImageUnscaled(buffer, _clientBounds.Location);
                }
            }
      public override void OnRender(Graphics g)
      {
#if !PocketPC      
             g.DrawImageUnscaled(localcache2, LocalPosition.X, LocalPosition.Y);
     
#else
        //    DrawImageUnscaled(g, Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            DrawImageUnscaled(g, Resources.marker, LocalPosition.X, LocalPosition.Y);
#endif
      }
Beispiel #37
0
 private void bitmapPanel_Paint(object sender, PaintEventArgs e)
 {
     System.Drawing.Graphics g = e.Graphics;
     g.SmoothingMode = SmoothingMode.HighQuality;
     g.DrawImageUnscaled(bm, bmOff);
     g.DrawLine(bmPen, bmX, bmY + 2, bmX, bmY + 200);
     g.DrawLine(bmPen, bmX, bmY - 2, bmX, bmY - 200);
     g.DrawLine(bmPen, bmX + 2, bmY, bmX + 200, bmY);
     g.DrawLine(bmPen, bmX - 2, bmY, bmX - 200, bmY);
 }
Beispiel #38
0
        private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            int wi = 0;

            if (m_Items.Count > 0)
            {
                SizeF [] size_entries = new SizeF[m_Items.Count];
                int      i;
                for (i = 0; i < m_Items.Count; i++)
                {
                    string s = ((PercentChartItem)(m_Items[i])).Text;
                    size_entries[i] = g.MeasureString(s, PFont);
                    if (size_entries[i].Width > wi)
                    {
                        wi = (int)(size_entries[i].Width);
                    }
                }
                int ps = this.Width - RoundCornerUpLeft.Width - SUpReleased.Width;
                for (i = 0; i < m_Items.Count; i++)
                {
                    PercentChartItem pi = (PercentChartItem)m_Items[i];
                    g.DrawString(pi.Text, PFont, PTextBrush, 2 + wi - size_entries[i].Width, 16 * i - PageStart);
                    if (pi.Percent > 0.0)
                    {
                        int bs;
                        int ci    = i % 8;
                        int pblen = (int)(pi.Percent * (ps - wi - 8 - BarImages[ci, 0].Width - BarImages[ci, 2].Width));
                        int pend  = pblen + wi + 4 + BarImages[ci, 0].Width;
                        for (bs = wi + 4 + BarImages[ci, 0].Width; (bs + BarImages[ci, 1].Width) < pend; bs += (int)BarImages[ci, 1].Width)
                        {
                            g.DrawImageUnscaled(BarImages[ci, 1], bs, i * 16 - PageStart);
                        }
                        g.DrawImage(BarImages[ci, 1], bs, i * 16 - PageStart, pend - bs, BarImages[ci, 1].Height);
                        g.DrawImageUnscaled(BarImages[ci, 0], wi + 4, i * 16 - PageStart);
                        g.DrawImageUnscaled(BarImages[ci, 2], pblen + wi + 4 + BarImages[ci, 0].Width, i * 16 - PageStart);
                    }
                }
            }
            g.DrawImageUnscaled(RoundCornerUpLeft, 0, 0);
            g.DrawImageUnscaled(RoundCornerDownLeft, 0, this.Height - RoundCornerDownLeft.Height);
        }
        public override void OnRender(Graphics g)
        {
            System.Drawing.Drawing2D.Matrix temp = g.Transform;

                g.TranslateTransform(LocalPosition.X, LocalPosition.Y);

                g.DrawImageUnscaled(global::SeaScanUAV.Properties.Resources.Glossyblueplane, global::SeaScanUAV.Properties.Resources.Glossyblueplane.Width / -2, global::SeaScanUAV.Properties.Resources.Glossyblueplane.Height / -2);//global::UAVVision.Properties.Resources.Glossyblueplane.Width / -2, global::UAVVision.Properties.Resources.Glossyblueplane.Height / -2);

                g.Transform = temp;
        }
Beispiel #40
0
 public void Draw(Graphics g)
 {
     int x = point.X;
     int y = point.Y;
     for (int i = 0; i < 5; i++)
     {
         g.DrawImageUnscaled(bmp, x, y);
         x += 60;
     }
 }
		/// <summary></summary>
		/// <param name="box"></param>
		/// <param name="g"></param>
		public void PaintBackground(Rectangle box, Graphics g) {
			if (img == null) {
				Resize(box);
			}
			g.DrawImageUnscaled(img, box.X, box.Y);
			//g.FillRectangle(brush, box);

			if (gloss != null) {
				gloss.PaintGloss(box, g);
			}
		}
        public void CleanUp(RenderTarget target, Graphics g, Map map)
        {
            target.EndDraw();
            
            var wicBitmap = (WICBitmap) target.Tag;
            using (var image = ConvertToBitmap(wicBitmap))
                g.DrawImageUnscaled(image, 0, 0);

            wicBitmap.Dispose();
            target.Dispose();
        }
 public static void DrawCardCost(Graphics g, Rectangle rect, string cost)
 {
     foreach(string symbol in Helper.GetSymbols(cost))
       {
     using(Image img = Program.LogicHandler.ServicesProvider.ImagesService.GetCardSymbol(symbol))
     {
       g.DrawImageUnscaled(img, rect);
       rect.X += img.Width;
     }
       }
 }
        /// <summary>
        /// Quantize an image and return the resulting output bitmap
        /// </summary>
        /// <param name="source">The image to quantize</param>
        /// <returns>A quantized version of the image</returns>
        public unsafe static byte[] Quantize(Image source)
        {
            // Get the size of the source image
            int height = source.Height;
            int width  = source.Width;

            // And construct a rectangle from these dimensions
            Rectangle bounds = new Rectangle(0, 0, width, height);

            // First off take a 32bpp copy of the image
            Bitmap copy = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            // Now lock the bitmap into memory
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(copy))
            {
                g.PageUnit = GraphicsUnit.Pixel;

                // Draw the source image onto the copy bitmap,
                // which will effect a widening as appropriate.
                g.DrawImageUnscaled(source, bounds);
            }

            BitmapData tt    = copy.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            byte *     data  = (byte *)tt.Scan0.ToPointer();
            int        index = 0;

            byte[] bytes = new byte[source.Width * source.Height * 4];



            for (int i = 0; i < source.Width; i++)
            {
                for (int j = 0; j < source.Height; j++)
                {
                    bytes[index] = data[index];
                    index++;

                    bytes[index] = data[index];
                    index++;

                    bytes[index] = data[index];
                    index++;

                    bytes[index] = data[index];
                    index++;
                }
            }

            copy.UnlockBits(tt);

            // Last but not least, return the output bitmap
            return(bytes);
        }
        public void PaintField(Graphics g)
        {
            using (Pen brownPen = new Pen(Color.Brown, 6.0F))
            {
                g.FillRectangle(Brushes.SkyBlue, 0, 0, _fieldForm.ClientSize.Width,
                    _fieldForm.ClientSize.Height / 2);
                g.FillEllipse(Brushes.Yellow, new RectangleF(50, 17, 70, 70));
                g.FillRectangle(Brushes.Green, 0, _fieldForm.ClientSize.Height / 2,
                    _fieldForm.ClientSize.Width, _fieldForm.ClientSize.Height / 2);
                g.DrawLine(brownPen, new Point(643, 0), new Point(643, 30));
                g.DrawImageUnscaled(_hiveOutside, 600, 20);

                foreach (Flower flower in _world.Flowers)
                    g.DrawImageUnscaled(_flower, flower.Location.X, flower.Location.Y);

                foreach (Bee bee in _world.Bees)
                    if (!bee.IsInsideHive)
                        g.DrawImageUnscaled(_beeAnimationSmall[_cell], bee.Location.X,
                            bee.Location.Y);
            }
        }
        public override void OnRender(Graphics g)
        {
            if (!Bearing.HasValue)
            {
                g.DrawImageUnscaled(global::Gipasoft.Stabili.UI.GeoLocation.Properties.Resources.shadow50, LocalPosition.X, LocalPosition.Y);
            }
            g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

            if (Bearing.HasValue)
            {
                g.RotateTransform(Bearing.Value);
                g.FillPolygon(Brushes.Lime, Arrow);
            }

            g.ResetTransform();

            if (!Bearing.HasValue)
            {
                g.DrawImageUnscaled(global::Gipasoft.Stabili.UI.GeoLocation.Properties.Resources.stabile_large, LocalPosition.X, LocalPosition.Y);
            }
        }
        /// <summary>
        /// Compiles the compiled tiles to a bitmap
        /// </summary>
        public Bitmap GetImage(Point offset, Size separation)
        {
            // If no tiles to draw, return nothing
            if (_tiles == null)
            {
                return(null);
            }

            int width  = TilesetWidth + (separation.Width * _cols) + offset.X;
            int height = TilesetHeight + (separation.Height * _rows) + offset.Y;

            // Create a new empty bitmap
            Bitmap tileset = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            // Create graphics
            System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(tileset);

            // Tile indexer
            int       index   = 0;
            int       offsetX = 0;
            int       offsetY = 0;
            int       cols    = _max.Width;
            int       rows    = _rows <= _max.Height ? _rows : _max.Height;
            Rectangle rect    = Rectangle.Empty;
            Point     dest    = Point.Empty;

            // Iterate through rows
            for (int row = 0; row < rows; row++)
            {
                // Iterate through columns
                for (int col = 0; col < cols; col++)
                {
                    // Calculate the destination
                    dest    = new Point(col * SnapSize.Width, row * SnapSize.Height);
                    offsetX = (col * separation.Width) + offset.X;
                    offsetY = (row * separation.Height) + offset.Y;
                    rect    = new Rectangle(dest.X + (col * separation.Width), dest.Y + (row * separation.Height), SnapSize.Width + separation.Width, SnapSize.Height + separation.Height);

                    // If the tile is within bounds, and is not empty, draw tile
                    if (index < _tiles.Count && _tiles[index] != null)
                    {
                        gfx.DrawImageUnscaled(_tiles[index], dest.X + offsetX, dest.Y + offsetY);
                    }

                    // Increment the indexer
                    index++;
                }
            }

            // Return tileset
            return(tileset);
        }
Beispiel #48
0
 System.Drawing.Icon CreateIcon(Image image)
 {
     if (image == null)
     {
         return(null);
     }
     using (System.Drawing.Bitmap newIcon = new System.Drawing.Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) {
         using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newIcon)) {
             g.DrawImageUnscaled(image, 0, 0, 16, 16);
             return(System.Drawing.Icon.FromHandle(newIcon.GetHicon()));
         }
     }
 }
Beispiel #49
0
        private static System.Drawing.Bitmap RotateImg
            (System.Drawing.Bitmap bmp, float angle)
        {
            angle = angle % 360;
            if (angle > 180)
            {
                angle -= 360;
            }
            float sin = (float)Math.Abs(Math.Sin(angle *
                                                 Math.PI / 180.0));                  // this function takes radians
            float cos          = (float)Math.Abs(Math.Cos(angle * Math.PI / 180.0)); // this one too
            float newImgWidth  = sin * bmp.Height + cos * bmp.Width;
            float newImgHeight = sin * bmp.Width + cos * bmp.Height;
            float originX      = 0f;
            float originY      = 0f;

            if (angle > 0)
            {
                if (angle <= 90)
                {
                    originX = sin * bmp.Height;
                }
                else
                {
                    originX = newImgWidth;
                    originY = newImgHeight - sin * bmp.Width;
                }
            }
            else
            {
                if (angle >= -90)
                {
                    originY = sin * bmp.Width;
                }
                else
                {
                    originX = newImgWidth - sin * bmp.Height;
                    originY = newImgHeight;
                }
            }
            System.Drawing.Bitmap newImg =
                new System.Drawing.Bitmap((int)newImgWidth, (int)newImgHeight);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newImg);
            g.Clear(System.Drawing.Color.White);
            g.TranslateTransform(originX, originY); // offset the origin to our calculated values
            g.RotateTransform(angle);               // set up rotate
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.DrawImageUnscaled(bmp, 0, 0);         // draw the image at 0, 0
            g.Dispose();
            return(newImg);
        }
Beispiel #50
0
        private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            int w = this.Width;
            int h = this.Height;

            System.Drawing.Graphics g = e.Graphics;
            if (IsDown)
            {
                int w2 = w - (B2UpLeft.Width + B2UpRight.Width) / 2;
                int h2 = h - (B2UpLeft.Height + B2DownLeft.Height) / 2;
                g.FillRectangle(BkgndBrush, B2UpLeft.Width / 2, B2UpLeft.Height / 2, w2 + 1, h2 + 1);
                g.DrawImage(B2Left, 0, 0, B2Left.Width / 2, h + 32);
                g.DrawImage(B2Right, w - B2Right.Width / 2, 0, B2Right.Width, h + 32);
                g.DrawImage(B2Up, 0, 0, w + 32, B2Up.Height / 2);
                g.DrawImage(B2Down, 0, h - B2Down.Height / 2, w + 32, B2Down.Height / 2);
                g.DrawImageUnscaled(B2UpLeft, 0, 0);
                g.DrawImageUnscaled(B2UpRight, w - B2UpRight.Width / 2, 0);
                g.DrawImageUnscaled(B2DownLeft, 0, h - B2DownLeft.Height / 2);
                g.DrawImageUnscaled(B2DownRight, w - B2DownRight.Width / 2, h - B2DownRight.Height / 2);
            }
            else
            {
                int w2 = w - (B2UpLeft.Width + B2UpRight.Width) / 2;
                int h2 = h - (B2UpLeft.Height + B2DownLeft.Height) / 2;
                g.FillRectangle(BkgndBrush, B1UpLeft.Width / 2, B1UpLeft.Height / 2, w2 + 1, h2 + 1);
                g.DrawImage(B1Left, 0, 0, B1Left.Width / 2, h + 32);
                g.DrawImage(B1Right, w - B1Right.Width / 2, 0, B1Right.Width, h + 32);
                g.DrawImage(B1Up, 0, 0, w + 32, B1Up.Height / 2);
                g.DrawImage(B1Down, 0, h - B1Down.Height / 2, w + 32, B1Down.Height / 2);
                g.DrawImageUnscaled(B1UpLeft, 0, 0);
                g.DrawImageUnscaled(B1UpRight, w - B1UpRight.Width / 2, 0);
                g.DrawImageUnscaled(B1DownLeft, 0, h - B1DownLeft.Height / 2);
                g.DrawImageUnscaled(B1DownRight, w - B1DownRight.Width / 2, h - B1DownRight.Height / 2);
            }
            if (m_Text.Length > 0)
            {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                SizeF textsize = g.MeasureString(m_Text, B1Font);
                if (IsDown)
                {
                    g.DrawString(m_Text, B1Font, B1TextBrush, (w - textsize.Width) * 0.5f + 1, (h - textsize.Height) * 0.5f + 1);
                }
                else
                {
                    g.DrawString(m_Text, B1Font, B1TextBrush, (w - textsize.Width) * 0.5f, (h - textsize.Height) * 0.5f);
                }
            }
        }
Beispiel #51
0
    public static string createModel(String[] array)
    {
        if (array.Length > 0)
        {
            System.Drawing.Bitmap   bm = new System.Drawing.Bitmap(400, array.Length * 90);
            System.Drawing.Graphics g  = System.Drawing.Graphics.FromImage(bm);
            g.Clear(System.Drawing.Color.White);
            int x = 100;
            int y = 10;
            System.Drawing.StringFormat f = new System.Drawing.StringFormat();
            f.Alignment     = System.Drawing.StringAlignment.Center;
            f.LineAlignment = System.Drawing.StringAlignment.Center;
            System.Drawing.Font font;
            System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(0, 40), new System.Drawing.Point(30, 130), System.Drawing.Color.GreenYellow, System.Drawing.Color.LemonChiffon);
            for (int i = 0; i < array.Length; i++)
            {
                font = new System.Drawing.Font("Arial Unicode MS", 10, System.Drawing.FontStyle.Regular);
                g.DrawImageUnscaled(System.Drawing.Image.FromFile(HttpContext.Current.Request.MapPath("tskOval.png")), x, y);
                g.DrawString(array[i].Substring(0, (array[i].Length > 52 ? 52 : array[i].Length)), font, System.Drawing.Brushes.Black, new System.Drawing.Rectangle(x + 30, y + 6, 172, 40), f);
                y += 85;
            }

            x = 100;
            y = 10;
            int y1, y2;
            for (int i = 1; i < array.Length; i++)
            {
                System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Black);
                p.Width = 1.5F;
                y1      = (((i) * 50) + y + ((i - 1) * 35));
                y2      = (((i) * 50) + y + ((i) * 35));
                g.DrawLine(p, 200, y1 + 2, 200, y2);
                System.Drawing.Point[] pns = new System.Drawing.Point[4];
                pns[0] = new System.Drawing.Point(195, y2 - 5);
                pns[1] = new System.Drawing.Point(200, y2);
                pns[2] = new System.Drawing.Point(205, y2 - 5);
                pns[3] = new System.Drawing.Point(195, y2 - 5);
                g.FillPolygon(System.Drawing.Brushes.Black, pns);

                // g.DrawString(((Node)SessionClass.Flow[i-1]).decision.Equals("True")?"Yes":"No", new System.Drawing.Font("Arial Unicode MS", 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, new System.Drawing.Point(205, y1 +6));
            }
            string res = HttpContext.Current.Server.MapPath("Results") + "\\User" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".png";
            bm.Save(res, System.Drawing.Imaging.ImageFormat.Png);
            return("Results/" + res.Replace(HttpContext.Current.Server.MapPath("Results") + "\\", ""));
        }
        else
        {
            return("");
        }
    }
Beispiel #52
0
        /// <summary>
        /// Makes a GDI+ bitmap from compressed Game Maker image data.
        /// </summary>
        /// <param name="imageData">The GM image data to convert.</param>
        /// <returns>A GDI+ bitmap.</returns>
        public static Bitmap GetBitmap(GMImage image)
        {
            // If not compressed, get bitmap normally
            if (image.Compressed == false)
            {
                return(PixelDataToBitmap(image.Data, image.Width, image.Height));
            }

            // Create new inflater
            Inflater inflater = new Inflater();

            // Image buffer
            byte[] result = new byte[image.Data.Length];

            // Set inflater input byte data
            inflater.SetInput(image.Data, 0, image.Data.Length);

            // Using memory stream
            using (MemoryStream ms = new MemoryStream())
            {
                // While the decompressor is not finished
                while (!inflater.IsFinished)
                {
                    // Get length of data
                    int length = inflater.Inflate(result);

                    // Write data result to byte array
                    ms.Write(result, 0, length);
                }

                // Reset position
                ms.Position = 0;

                // Get bitmap from stream
                Bitmap bitmap = (Bitmap)Bitmap.FromStream(ms);

                // Create a backbuffer image to convert the bitmap for the screen
                System.Drawing.Graphics gfx = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
                Bitmap buffer = new Bitmap(bitmap.Width, bitmap.Height, gfx);
                gfx.Dispose();

                // Copy original bitmap to new backbuffer
                gfx = System.Drawing.Graphics.FromImage(buffer);
                gfx.DrawImageUnscaled(bitmap, new Point(0, 0));
                gfx.Dispose();

                // Return bitmap
                return(buffer);
            }
        }
Beispiel #53
0
        public void ExecuteDrawBitmap()
        {
            lock (_syncRoot)
            {
                int x = -MaxLength / 2 + RandomInteger.NextInteger(MaxWindowWidth + MaxLength);
                int y = -MaxLength / 2 + RandomInteger.NextInteger(MaxWindowHeight + MaxLength);

#if !CompactFramework
                _outputGraphics.DrawImageUnscaled(Images[RandomInteger.NextInteger(0, Images.Length)], x, y);
#else
                _outputGraphics.DrawImage(Images[RandomInteger.NextInteger(0, Images.Length)], x, y);
#endif
            }
        }
        private void DrawPadButton(System.Drawing.Graphics graphics, PointF point, Image icon, string label, bool pressed, bool enabled)
        {
            // Use relative positions so we can center the the entire drawing later.

            float iconX      = 0;
            float iconY      = 0;
            float iconWidth  = icon.Width;
            float iconHeight = icon.Height;

            var labelRectangle = MeasureString(graphics, label, _labelsTextFont);

            float labelPositionX = iconWidth + 8 - labelRectangle.X;
            float labelPositionY = (iconHeight - labelRectangle.Height) / 2 - labelRectangle.Y - 1;

            float fullWidth  = labelPositionX + labelRectangle.Width + labelRectangle.X;
            float fullHeight = iconHeight;

            // Convert all relative positions into absolute.

            float originX = (int)(point.X - fullWidth / 2);
            float originY = (int)(point.Y - fullHeight / 2);

            iconX += originX;
            iconY += originY;

            var labelPosition = new PointF(labelPositionX + originX, labelPositionY + originY);

            graphics.DrawImageUnscaled(icon, (int)iconX, (int)iconY);

            DrawString(graphics, label, _labelsTextFont, _textNormalBrush, labelPosition);

            GraphicsPath frame = new GraphicsPath();

            frame.AddRectangle(new RectangleF(originX - 2 * _padPressedPenWidth, originY - 2 * _padPressedPenWidth,
                                              fullWidth + 4 * _padPressedPenWidth, fullHeight + 4 * _padPressedPenWidth));

            if (enabled)
            {
                if (pressed)
                {
                    graphics.DrawPath(_padPressedPen, frame);
                }
            }
            else
            {
                // Just draw a semi-transparent rectangle on top to fade the component with the background.
                // TODO (caian): This will not work if one decides to add make background semi-transparent as well.
                graphics.FillPath(_disabledBrush, frame);
            }
        }
Beispiel #55
0
    public static byte[] osmPath(string path)
    {
        //Debug.Log("GISlayer start: " + path);
        Bitmap bmp = new Bitmap(path);

        //Bitmap bmpIn = (Bitmap)Bitmap.FromFile(inputFileName);

        Bitmap converted = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format24bppRgb);

        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(converted))
        {
            // Prevent DPI conversion
            g.PageUnit = GraphicsUnit.Pixel;
            // Draw the image
            g.DrawImageUnscaled(bmp, 0, 0);
        }
        bmp = converted;
        //Debug.Log("GISlayer bitmap");
        Rectangle  rect    = new Rectangle(0, 0, bmp.Width, bmp.Height);
        BitmapData bmpData =
            bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);

        int bytes = Math.Abs(bmpData.Stride) * bmp.Height;

        byte[] rgbValues = new byte[bytes];
        //Debug.Log("GISlayer copy");
        // Copy the RGB values into the array.
        Marshal.Copy(bmpData.Scan0, rgbValues, 0, bytes);

        byte[] rgbaValues = new byte[bmp.Width * bmp.Height * 4];
        //Debug.Log("GISlayer mem");
        for (int x = 0; x < bmp.Width; x++)
        {
            for (int y = 0; y < bmp.Width; y++)
            {
                rgbaValues[(x + bmp.Width * y) * 4 + 0] = rgbValues[(x + bmp.Width * (y)) * 3 + 2];
                rgbaValues[(x + bmp.Width * y) * 4 + 1] = rgbValues[(x + bmp.Width * (y)) * 3 + 1];
                rgbaValues[(x + bmp.Width * y) * 4 + 2] = rgbValues[(x + bmp.Width * (y)) * 3 + 0];
                rgbaValues[(x + bmp.Width * y) * 4 + 3] = 255;
            }
        }

        /*byte[] argbTex= new byte[bmp.Width* bmp.Height* 4];
         * for (int i = 0; i < rgbValues.Length; i+=3)
         * {
         *  rgbTex[i];
         * }*/
        //Debug.Log("GISlayer end");
        return(rgbaValues);
    }
Beispiel #56
0
 private void TryExpand(double x, double y, double width, double height, float penSize)
 {
     if (x + width + penSize > bitmap.Width || y + height + penSize > bitmap.Height)
     {
         Bitmap newBitmap = new Bitmap((int)Math.Max(Math.Ceiling(x + width + penSize), bitmap.Width), (int)Math.Max(Math.Ceiling(y + height + penSize), bitmap.Height));
         using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap)) {
             g.DrawImageUnscaled(bitmap, new Point(0, 0));
         }
         Bitmap oldBitmap = bitmap;
         bitmap = newBitmap;
         oldBitmap.Dispose();
         Changed?.Invoke(this, EventArgs.Empty);
     }
 }
Beispiel #57
0
        private void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            int h, w, aw, hd, bw, bb, ws;

            System.Drawing.Graphics g = e.Graphics;
            h  = this.Height;
            w  = this.Width;
            aw = w - (PGreyHead.Width + PGreyTail.Width);
            hd = (h - PGreyBody.Height) / 2;
            g.FillRectangle(BkgndBrush, 0, 0, w, h);
            if (w > 0)
            {
                g.DrawImage(PGreyBody, 0, hd, w, PGreyBody.Height);
            }
            g.DrawImageUnscaled(PGreyHead, 0, hd);
            g.DrawImageUnscaled(PGreyTail, w - PGreyTail.Width, hd);
            if (m_Percent > 0.0)
            {
                bw = (int)(Percent * aw);
                if (bw > aw)
                {
                    bw = aw;
                }
                g.DrawImageUnscaled(PRedHead, 0, hd);
                ws = PRedBody.Width;
                for (bb = ws; bb <= bw; bb += PRedBody.Width)
                {
                    g.DrawImageUnscaled(PRedBody, PRedHead.Width + bb - ws, hd);
                }
                if (bb - ws < bw)
                {
                    g.DrawImage(PRedBody, PRedHead.Width + bb - ws, hd, bw - bb + ws, PRedBody.Height);
                }
                g.DrawImageUnscaled(PRedTail, bw + PRedHead.Width, hd);
            }
        }
Beispiel #58
0
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            DataRowView drv = source.List[rowNum] as DataRowView;
            Image       img = null;

            if (drv != null)
            {
                img = imageMap[drv[this.MappingName]] as Image;
            }
            g.FillRectangle(backBrush, bounds);
            bounds.Offset(2, 1);
            if (img != null)
            {
                g.DrawImageUnscaled(img, bounds);
            }
        }
        /// <summary>
        /// Paints the double buffer11.
        /// </summary>
        /// <param name="ControlGraphics">The control graphics.</param>
        private void PaintDoubleBuffer11(System.Drawing.Graphics ControlGraphics)
        {
            switch (Mode)
            {
            case TestMode.Test:
                LunchGraphicTest(BufferGraphics);
                break;

            case TestMode.PaintOverridden:
                MainPaint(BufferGraphics);
                break;
            }

            // this draws the image from the buffer into the form area
            // (note: DrawImageUnscaled is the fastest way)
            ControlGraphics.DrawImageUnscaled(BackBuffer, 0, 0);
        }
Beispiel #60
0
        /// <summary>
        /// Possibly the slowest ever implementation of a text draw routine, but enables pixel-perfect positioning of the text.
        /// </summary>
        /// <param name="graphics">The text is drawn into this drawing object.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="brush">The brush to use.</param>
        /// <param name="fontFamily">Name of the font family.</param>
        /// <param name="fontSize">Maximum font size: if width/height specified, text will be shrunk from this.</param>
        /// <param name="fontStyle">Font style in which to draw the text.</param>
        /// <param name="x">X coordinate of the anchor point.</param>
        /// <param name="y">Y coordinate of the anchor point (see also <paramref name="baseline"/>).</param>
        /// <param name="anchor">Specifies where the anchor point is positioned relative to the text.</param>
        /// <param name="width">Maximum text width, in pixels. Text is shurnk if necessary to fit in.</param>
        /// <param name="height">Maximum text height, in pixels. Text is shurnk if necessary to fit in.</param>
        /// <param name="baseline">If false, the vertical anchoring is done on the topmost/bottommost pixel. If true, top/bottom will instead position the baseline consistently,
        /// so that the top of the tallest letter or the bottom of the lowest descender is located on the specified pixel.</param>
        /// <returns>A rectangle describing the extent of the text's pixels.</returns>
        public static PixelRect DrawString(this D.Graphics graphics, string text, D.Brush brush, string fontFamily, double fontSize, D.FontStyle fontStyle,
                                           int x, int y, Anchor anchor, int?width = null, int?height = null, bool baseline = false)
        {
            BitmapGdi bmp;
            PixelRect size;

            double fontSizeMin = 0;
            double fontSizeMax = fontSize;
            double threshold   = graphics.TextRenderingHint == D.Text.TextRenderingHint.AntiAlias ? 0.07 : 0.5;

            while (true)
            {
                var font = new D.Font(fontFamily, (float)fontSize, fontStyle);
                bmp  = graphics.TextToBitmap(text, font, brush);
                size = baseline
                    ? bmp.PreciseWidth().WithTopBottom(graphics.TextToBitmap("Mgy345", font, D.Brushes.White).PreciseHeight())
                    : bmp.PreciseSize();

                if (width == null && height == null)
                {
                    break;
                }
                if ((width == null || size.Width <= width.Value) && (height == null || size.Height <= height.Value))
                {
                    fontSizeMin = fontSize; // Fits
                }
                else
                {
                    fontSizeMax = fontSize; // Doesn't fit
                }
                if (fontSize == fontSizeMin && fontSizeMax - fontSizeMin <= threshold)
                {
                    break;
                }
                fontSize = (fontSizeMin + fontSizeMax) / 2;
            }

            var anchr = (AnchorRaw)anchor;

            x -= anchr.HasFlag(AnchorRaw.Right) ? size.Width - 1 : anchr.HasFlag(AnchorRaw.Center) ? (size.Width - 1) / 2 : 0;
            y -= anchr.HasFlag(AnchorRaw.Bottom) ? size.Height - 1 : anchr.HasFlag(AnchorRaw.Mid) ? (size.Height - 1) / 2 : 0;

            graphics.DrawImageUnscaled(bmp.Bitmap, x - size.Left, y - size.Top);
            GC.KeepAlive(bmp);
            return(size.Shifted(x, y));
        }