Flush() public method

public Flush ( ) : void
return void
Esempio n. 1
0
        void UpdateString()
        {
            if (!m_texture.Initialized)
            {
                return;
            }

            int width  = m_texture.Width;
            int height = m_texture.Height;

            Rectangle rect = new Rectangle(0, 0, width, height);

            Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            graphics.Clip = new Region(rect);

            graphics.DrawString(m_text, m_font, m_brush, 0.0f, 0.0f);
            graphics.Flush();

            BitmapData data = bitmap.LockBits(rect,
                                              ImageLockMode.ReadOnly,
                                              System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GraphicsCommand.UpdateTextureRGBA(m_texture, data.Scan0);

            bitmap.UnlockBits(data);

            m_updateString = false;

            bitmap.Dispose();
            graphics.Dispose();
        }
        /// <summary>
        /// Copy to canvas
        /// </summary>
        /// <param name="sourceBitmap">Set source Bitmap</param>
        /// <param name="canvasWidthLenght">Set canvas Width and Length</param>
        /// <returns></returns>
        public static System.Drawing.Bitmap CopyToSquareCanvas(this System.Drawing.Bitmap sourceBitmap, int canvasWidthLenght)
        {
            float ratio   = 1.0f;
            int   maxSide = sourceBitmap.Width > sourceBitmap.Height ?
                            sourceBitmap.Width : sourceBitmap.Height;

            ratio = (float)maxSide / (float)canvasWidthLenght;

            System.Drawing.Bitmap bitmapResult = (sourceBitmap.Width > sourceBitmap.Height ?
                                                  new System.Drawing.Bitmap(canvasWidthLenght, (int)(sourceBitmap.Height / ratio))
                                    : new System.Drawing.Bitmap((int)(sourceBitmap.Width / ratio), canvasWidthLenght));

            using (System.Drawing.Graphics graphicsResult = System.Drawing.Graphics.FromImage(bitmapResult))
            {
                graphicsResult.CompositingQuality = CompositingQuality.HighQuality;
                graphicsResult.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphicsResult.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                graphicsResult.DrawImage(sourceBitmap,
                                         new Rectangle(0, 0,
                                                       bitmapResult.Width, bitmapResult.Height),
                                         new Rectangle(0, 0,
                                                       sourceBitmap.Width, sourceBitmap.Height),
                                         GraphicsUnit.Pixel);
                graphicsResult.Flush();
            }

            return(bitmapResult);
        }
Esempio n. 3
0
        private Image DrawOutsetShadow(Color color, Rectangle shadowCanvasArea)
        {
            Rectangle rOuter = shadowCanvasArea;
            Rectangle rInner = new Rectangle(shadowCanvasArea.X + (-Offset.X - 1), shadowCanvasArea.Y + (-Offset.Y - 1), shadowCanvasArea.Width - (-Offset.X * 2 - 1), shadowCanvasArea.Height - (-Offset.Y * 2 - 1));

            Bitmap img = new Bitmap(rOuter.Width, rOuter.Height, PixelFormat.Format32bppArgb);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);
            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            using (Brush bgBrush = new SolidBrush(Color.FromArgb(30, Color.Black)))
            {
                g.FillRectangle(bgBrush, rOuter);
            }
            using (Brush bgBrush = new SolidBrush(Color.FromArgb(60, Color.Black)))
            {
                g.FillRectangle(bgBrush, rInner);
            }

            g.Flush();
            g.Dispose();

            return(img);
        }
Esempio n. 4
0
        public static void SetupGlide(int width, int height, int bitsPerPixel, int orientationDeg, DisplayController displayController)
        {
            Hdc = displayController.Hdc;
            //HardwareProvider.HwProvider.GetLCDMetrics(out width, out height, out bitsPerPixel, out orientationDeg);
            LCD = new Size()
            {
                Width = width, Height = height
            };
            screen     = System.Drawing.Graphics.FromHdc(Hdc);// new (width, height);
            IsEmulator = false;

            /*
             * // Are we in the emulator?
             * if (SystemInfo.SystemID.SKU == 3)
             *  IsEmulator = true;
             * else
             *  IsEmulator = false;
             */
            FitToScreen = false;

            Keyboard          = DefaultKeyboard();
            MessageBoxManager = new MessageBoxManager();

            // Show loading
            System.Drawing.Bitmap loading = Resources.GetBitmap(Resources.BitmapResources.loading);

            screen.DrawImage(loading, (LCD.Width - loading.Width) / 2, (LCD.Height - loading.Height) / 2, loading.Width, loading.Height);
            screen.Flush();
            //screen.Flush(0,0,width,height);
        }
Esempio n. 5
0
        public void Refresh()
        {
            CanvasRoot.Children.Clear();
            if (dlx == 0 || dly == 0)
            {
                return;
            }

            if (ChartDataSeries.Any())
            {
                var points = new List <PointF>();
                ChartDataSeries.ToList().ForEach(
                    p =>
                {
                    points.Add(Normalize(p));
                }
                    );

                if (points.Count() <= 1)
                {
                    return;
                }


                WriteableBitmap bitmap = new WriteableBitmap
                                         (
                    (int)this.RenderSize.Width,
                    (int)this.RenderSize.Height,
                    96, 96,
                    PixelFormats.Bgra32,
                    null
                                         );
                Image figure = new Image {
                    Source = bitmap
                };
                bitmap.Lock();
                using (System.Drawing.Bitmap buff = new System.Drawing.Bitmap(
                           (int)bitmap.Width,
                           (int)bitmap.Height,
                           bitmap.BackBufferStride,
                           System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                           bitmap.BackBuffer))
                {
                    // GDI+ Drawing
                    using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(buff))
                    {
                        Color color = (Foreground as SolidColorBrush).Color;
                        var   brush = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);
                        var   pen   = new System.Drawing.Pen(brush, 1); //1 is minimum, bigger thickness could effect performance
                        graphics.DrawLines(pen, points.ToArray());
                        graphics.Flush();
                    }
                }

                bitmap.AddDirtyRect(new Int32Rect(0, 0, (int)bitmap.Width, (int)bitmap.Height));
                bitmap.Unlock();

                CanvasRoot.Children.Add(figure);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 对一个WebBrowser进行截图
        /// </summary>
        /// <param name="targetBrowser">我这里用的是Forms的WebBrowser,如果是wpf的,请自己改成Controls并调整参数</param>
        /// <returns></returns>
        public static ImageSource BrowserSnapShot(System.Windows.Controls.WebBrowser targetBrowser)
        {
            try
            {
                // 获取宽高
                int screenWidth  = (int)targetBrowser.ActualWidth;
                int screenHeight = (int)targetBrowser.ActualHeight;

                IntPtr myIntptr = targetBrowser.Handle;
                int    hwndInt  = myIntptr.ToInt32();
                IntPtr hwnd     = myIntptr;
                //创建图形
                System.Drawing.Bitmap   bm = new System.Drawing.Bitmap(screenWidth, screenHeight, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
                System.Drawing.Graphics g  = System.Drawing.Graphics.FromImage(bm);
                IntPtr hdc = g.GetHdc();

                //调用api 把hwnd的内容用图形绘制到hdc 如果你有代码洁癖 可以不使用api 使用g.CopyFromScreen,请自行研究
                bool result = PrintWindow(hwnd, hdc, 0);
                g.ReleaseHdc(hdc);
                g.Flush();


                if (result == true) //成功 转换并返回ImageSource
                {
                    ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                    MemoryStream         stream = new MemoryStream();
                    bm.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                    return((ImageSource)imageSourceConverter.ConvertFrom(stream));
                }
            }
            catch { }
            return(null);
        }
Esempio n. 7
0
        public void DrawPolygon(PointF[] points, System.Drawing.Color color)
        {
            this.bitmap.Lock();

            using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height,
                                                                this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb,
                                                                this.bitmap.BackBuffer))
            {
                using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap))
                {
                    backBufferGraphics.SmoothingMode      = GDI.Drawing2D.SmoothingMode.HighSpeed;
                    backBufferGraphics.CompositingQuality = GDI.Drawing2D.CompositingQuality.HighSpeed;

                    //backBufferGraphics.DrawLines(new System.Drawing.Pen(LINE_COLOR, (float)0.2), points);  //add
                    if (points[0] == points[points.Count() - 1])
                    {
                        backBufferGraphics.FillClosedCurve(new GDI.SolidBrush(color), points, GDI.Drawing2D.FillMode.Winding);
                        //backBufferGraphics.FillPolygon(FILL_COLOR, points, GDI.Drawing2D.FillMode.Alternate);
                    }
                    backBufferGraphics.Flush();
                }
            }
            this.bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            this.bitmap.Unlock();
        }
Esempio n. 8
0
        public static Image LoadImage(string text)
        {
            System.Drawing.Bitmap   bmp     = new System.Drawing.Bitmap(1, 1);
            System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bmp);
            System.Drawing.Font     font    = new System.Drawing.Font("Arial", 11, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic);
            int width  = Convert.ToInt32(graphic.MeasureString(text, font).Width);
            int height = Convert.ToInt32(graphic.MeasureString(text, font).Height);

            bmp     = new System.Drawing.Bitmap(height, width);
            graphic = System.Drawing.Graphics.FromImage(bmp);
            graphic.Clear(System.Drawing.Color.White);
            graphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            graphic.TranslateTransform(0, width);
            graphic.RotateTransform(270);
            graphic.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.Fuchsia), 0, 0);
            graphic.Flush();

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            // return ms.ToArray();

            Image returnImage = Image.FromStream(ms);

            return(returnImage);
        }
Esempio n. 9
0
        public BitmapTextureSource Write(string s, float size, Color fg)
        {
            Bitmap       tmp = new Bitmap(1, 1);
            StringFormat fmt = new StringFormat()
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            GDIGraphics tmpG = GDIGraphics.FromImage(tmp);
            Font        fnt  = new Font(familyName, size);
            SizeF       si   = tmpG.MeasureString(s, fnt);

            tmpG.Dispose();
            tmp.Dispose();

            Bitmap bmp = new Bitmap((int)si.Width, (int)si.Height);

            bmp.MakeTransparent();

            tmpG = GDIGraphics.FromImage(bmp);
            tmpG.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            tmpG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            tmpG.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            tmpG.DrawString(s, fnt, new SolidBrush(fg), 0, 0);
            tmpG.Flush();
            tmpG.Dispose();

            var t = new BitmapTextureSource(bmp, 0);

            bmp.Dispose();
            return(t);
        }
Esempio n. 10
0
        /*
         * 函数功能:DrawLine
         * 函数功能介绍:绘制线条
         * 形参列表:points(PointF[],线条的屏幕坐标)
         * 返回值:void
         */
        public BitmapImage DrawLine(PointF[] points, System.Drawing.Color color, int _width, int _heigh)
        {
            System.Drawing.Pen pen = new System.Drawing.Pen(new GDI.SolidBrush(color), (float)2);

            width  = _width;
            height = _heigh;

            this.bitmap.Lock();

            using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height,
                                                                this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb,
                                                                this.bitmap.BackBuffer))
            {
                using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap))
                {
                    backBufferGraphics.SmoothingMode      = GDI.Drawing2D.SmoothingMode.HighSpeed;
                    backBufferGraphics.CompositingQuality = GDI.Drawing2D.CompositingQuality.HighSpeed;

                    pen = new System.Drawing.Pen(new GDI.SolidBrush(System.Drawing.Color.Red), (float)2);
                    backBufferGraphics.DrawLines(pen, points);
                    backBufferGraphics.Flush();
                }
            }
            this.bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            this.bitmap.Unlock();

            Bitmap _bitmap = ConvertWriteableBitmapToBitmap(bitmap);

            //SaveXXX();
            return(BitmapToBitmapImage(_bitmap));
        }
Esempio n. 11
0
        /// <summary>Adds a textual string to a bitmap image</summary>
        /// <param name="bitmap">The bitmap image to add the text to, or a null reference if a new image is to be created</param>
        /// <param name="txt">The text to overlay</param>
        /// <param name="fontname">The name of the font to use</param>
        /// <param name="fontsize">The size in points of the font</param>
        /// <param name="bgcolor">The background color to use (Only relevant if creating a new image)</param>
        /// <param name="fcolor">The font color to use</param>
        /// <param name="Padding">The padding to use, or alternatively the X,Y inset if overlaying text</param>
        public static Bitmap AddTextToBitmap(Bitmap bitmap, string txt, string fontname, int fontsize, Color bgcolor, Color fcolor, Vector2 Padding)
        {
            bool  overlay = true;
            SizeF size;

            if (bitmap == null)
            {
                bitmap  = new Bitmap(1024, 1024);
                overlay = false;
            }

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
            {
                Font font = new Font(fontname, fontsize);
                size = graphics.MeasureString(txt, font);
                if (!overlay)
                {
                    graphics.FillRectangle(new SolidBrush(bgcolor), 0, 0, size.Width + (int)Padding.X * 2, size.Height + (int)Padding.Y * 2);
                }

                graphics.DrawString(txt, font, new SolidBrush(fcolor), (int)Padding.X, (int)Padding.Y);
                graphics.Flush();
                font.Dispose();
            }

            if (!overlay)
            {
                Rectangle cropArea = new Rectangle(0, 0, (int)size.Width + (int)Padding.X * 2, (int)size.Height + (int)Padding.Y * 2);
                return(bitmap.Clone(cropArea, bitmap.PixelFormat));
            }

            return(bitmap);
        }
Esempio n. 12
0
        public static void RenderClock(RectangleF area, Graphics graphics, bool isPreview)
        {
            int tempBrushWeight = isPreview ? 2 : brushWeight;
            int tempSpacing = isPreview ? 4 : spacing;

            Pen penSecond = new Pen(new SolidBrush(Color.FromArgb(alpha, secondColor)), tempBrushWeight);
            Pen penMinute = new Pen(new SolidBrush(Color.FromArgb(alpha, minuteColor)), tempBrushWeight);
            Pen penHour = new Pen(new SolidBrush(Color.FromArgb(alpha, hourColor)), tempBrushWeight);

            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            // Formula
            // 1. Subdivide the circle by the total count of each sec, min or hours
            // 2. Multiply the value from 1. by the current sec, min or hour
            // 3.  ==> For ex, for sec (360/60)*current second

            DateTime now = DateTime.Now;

            // Draw second arc
            // For smooth animation consider the current seconds in terms of floating point number like below instead of this --> graphics.DrawArc(penSecond, area, -90f, 6*now.Second);
            graphics.DrawArc(penSecond, area, -90f, 6F * ((now.Second + now.Millisecond / 1000F)));

            // Draw minute arc
            graphics.DrawArc(penMinute, new RectangleF(area.X + tempSpacing * 2, area.Y + tempSpacing * 2, area.Width - tempSpacing * 4, area.Height - tempSpacing * 4), -90f, 6F * (now.Minute + now.Second / 60F));

            int hour = enable24HourFormat ? int.Parse(now.ToString("HH")) : int.Parse(now.ToString("%h"));
            float hourMultiplier = enable24HourFormat ? 360 / 24f : 360 / 12f;

            // Draw hour arc
            graphics.DrawArc(penHour, new RectangleF(area.X + tempSpacing * 4, area.Y + tempSpacing * 4, area.Width - tempSpacing * 8, area.Height - tempSpacing * 8), -90f, hourMultiplier * (hour + now.Minute / 60F));

            graphics.Flush();
        }
        protected override void OnRender(DrawingContext dc)
        {
            if (bitmap == null)
            {
                this.width  = (int)RenderSize.Width;
                this.height = (int)RenderSize.Height;
                this.bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr24, null);

                this.bitmap.Lock();
                using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height,
                                                                    this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb,
                                                                    this.bitmap.BackBuffer))
                {
                    using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap))
                    {
                        backBufferGraphics.SmoothingMode      = GDI.Drawing2D.SmoothingMode.HighSpeed;
                        backBufferGraphics.CompositingQuality = GDI.Drawing2D.CompositingQuality.HighSpeed;

                        backBufferGraphics.Clear(GDI.Color.White);

                        backBufferGraphics.Flush();
                    }
                }
                this.bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
                this.bitmap.Unlock();

                this.prices = new float[(int)(this.width / this.dx)];
            }
            dc.DrawImage(bitmap, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            base.OnRender(dc);
        }
Esempio n. 14
0
        public static Cursor CreateCrossCursor()
        {
            const int w = 25;
            const int h = 25;

            var bmp = new System.Drawing.Bitmap(w, h);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.SmoothingMode     = SmoothingMode.Default;
            g.InterpolationMode = InterpolationMode.High;

            var pen = new System.Drawing.Pen(System.Drawing.Brushes.Black, 2);

            g.DrawLine(pen, new Point(12, 0), new Point(12, 8));   // vertical line
            g.DrawLine(pen, new Point(12, 17), new Point(12, 25)); // vertical line
            g.DrawLine(pen, new Point(0, 12), new Point(8, 12));   // horizontal line
            g.DrawLine(pen, new Point(16, 12), new Point(24, 12)); // horizontal line
            g.DrawLine(pen, new Point(12, 12), new Point(12, 13)); // Middle dot

            g.Flush();
            g.Dispose();
            pen.Dispose();

            var c = CreateBmpCursor(bmp);

            bmp.Dispose();

            return(c);
        }
Esempio n. 15
0
 private static void DrawTextOnBitmap(System.Drawing.Bitmap objBmpImage, Graphics objGraphics, string text, Font objFont, InputOptions options)
 {
     objGraphics = Graphics.FromImage(objBmpImage);
     objGraphics.Clear(ColorTranslator.FromHtml(options.BackgroundColor));
     objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
     objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
     objGraphics.DrawString(text, objFont, new SolidBrush(ColorTranslator.FromHtml(options.TextColor)), 0, 0);
     objGraphics.Flush();
 }
Esempio n. 16
0
 public ed.Bitmap LockEtoBitmap()
 {
     sdGraphics?.Flush();
     using (var ms = new MemoryStream())
     {
         sdBuffer.Save(ms, sd.Imaging.ImageFormat.Png);
         return(new ed.Bitmap(ms.ToArray()));
     }
 }
Esempio n. 17
0
 public void Flush()
 {
     if (isD3D)
     {
         d3d.Flush();
     }
     else
     {
         gdi.Flush();
     }
 }
        protected override void ClearShadow()
        {
            Bitmap img = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img);
            g.Clear(Color.Transparent);
            g.Flush();
            g.Dispose();
            SetBitmap(img, 255);
            img.Dispose();
        }
Esempio n. 19
0
        /* Draws a ractangle with given sides, coordinates Position.X & .Y
         * using given color) */

        public override void Draw(System.Drawing.Graphics g)
        {
            // Create a pen
            System.Drawing.Pen p = new System.Drawing.Pen(RgbColor);
            int x = Position.X;
            int y = Position.Y;

            // Draw a rectangle
            g.DrawRectangle(p, x, y, Width, Height);
            g.Flush();
        }
Esempio n. 20
0
        /// <summary>
        /// Get ARGB
        /// </summary>
        /// <param name="sourceImage">Set source bitmap</param>
        /// <returns></returns>
        public static System.Drawing.Bitmap GetArgbCopy(Image sourceImage)
        {
            System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb);

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmpNew))
            {
                graphics.DrawImage(sourceImage, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), GraphicsUnit.Pixel);
                graphics.Flush();
            }

            return(bmpNew);
        }
Esempio n. 21
0
 /*
  * 函数功能:ClearBitmap
  * 函数功能介绍:清除屏幕显示
  * 形参列表:无
  * 返回值:void
  */
 public void ClearBitmap()
 {
     using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height,
                                                         this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb,
                                                         this.bitmap.BackBuffer))
     {
         using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap))
         {
             backBufferGraphics.Clear(GDI.Color.Transparent);
             backBufferGraphics.Flush();
         }
     }
 }
Esempio n. 22
0
        private void draw_invalidData()
        {
            drawBitmap          = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            g                   = Graphics.FromImage(drawBitmap);
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            g.DrawString("Invalid Data", new Font("Tahoma", 60), Brushes.Black, 0, 0);
            g.Flush();
            pictureBox1.Image     = drawBitmap;
            pictureBox1.Image.Tag = "jhn";
        }
Esempio n. 23
0
        public virtual void DrawString(RectangleF area, Graphics g, String text, FontFamily ff, Color c)
        {
            SizeF size = g.MeasureString(text, new Font(ff, 32));
            double difX = (size.Width - area.Width) / -size.Width;

            double difY = (size.Height - area.Height) / -size.Height;
            float finalFontSize = 32 + (float)(32 * Math.Min(difX, difY));
            SizeF finalSize = g.MeasureString(text, new Font(ff, finalFontSize));

            g.DrawString(text, new Font(ff, finalFontSize), new SolidBrush(c),
                new PointF((area.Width - finalSize.Width) / 2 + area.Left, (area.Height - finalSize.Height) / 2 + area.Height));
            g.Flush();
        }
Esempio n. 24
0
        private void AddText(Bitmap bmp, string text, int x, int y)
        {
            var font = new Font("Arial", 8);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            SizeF      stringSize     = g.MeasureString(text, font);
            RectangleF rectf          = new RectangleF(x, y - stringSize.Height / 2, stringSize.Width, stringSize.Height);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            g.DrawString(text, font, Brushes.White, rectf);
            g.Flush();
        }
Esempio n. 25
0
        protected override void OnRender(DrawingContext dc)
        {
            if (bitmap == null)
            {
                this.width  = (int)RenderSize.Width;
                this.height = (int)RenderSize.Height;
                this.bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr24, null);

                this.bitmap.Lock();
                using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height,
                                                                    this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb,
                                                                    this.bitmap.BackBuffer))
                {
                    using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap))
                    {
                        backBufferGraphics.SmoothingMode      = GDI.Drawing2D.SmoothingMode.HighSpeed;
                        backBufferGraphics.CompositingQuality = GDI.Drawing2D.CompositingQuality.HighSpeed;

                        backBufferGraphics.Clear(GDI.Color.White);

                        float time_width  = width / 25;
                        float vlot_height = height / 10;

                        pen = new GDI.Pen(GDI.Color.Gray);
                        for (int i = 0; i < 26; i++)
                        {
                            backBufferGraphics.DrawLine(pen,
                                                        new GDI.PointF(i * time_width, 0),
                                                        new GDI.PointF(i * time_width, height));
                        }

                        for (int i = 0; i < 11; i++)
                        {
                            backBufferGraphics.DrawLine(pen,
                                                        new GDI.PointF(0, vlot_height * i),
                                                        new GDI.PointF(width, vlot_height * i));
                        }

                        backBufferGraphics.Flush();
                    }
                }
                this.bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
                this.bitmap.Unlock();

                prices        = new float[(int)(this.width / this.dx)];
                this.exchange = new float[(int)(this.width / this.dx)];
            }
            dc.DrawImage(bitmap, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            base.OnRender(dc);
        }
Esempio n. 26
0
 private void imageXView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (isDrawingWithPen && isMouseDrawing)
     {
         PointF drawPoint = imageXView1.Translate(new System.Drawing.Point(e.X, e.Y), Accusoft.ImagXpressSdk.TranslateType.ViewToPixel);
         if (drawPoint.X >= 0 && drawPoint.Y >= 0)
         {
             System.Drawing.Graphics g = imageXView1.Image.GetGraphics();
             g.DrawLine(System.Drawing.Pens.Black, LastDrawPoint, drawPoint);
             g.Flush();
             imageXView1.Image.ReleaseGraphics(true);
             LastDrawPoint = drawPoint;
         }
     }
 }
Esempio n. 27
0
        public void draw(Graphics graphics, Bitmap bmp, int offsetX, int offsetY)
        {
            graphics.Clear(Color.White);
            for (double i = 0; i <= 1; i += stepLength)
            {
                int x = PointPostion(i, PointPostion(i, p1.X, p2.X), PointPostion(i, p2.X, p3.X));
                int y = PointPostion(i, PointPostion(i, p1.Y, p2.Y), PointPostion(i, p2.Y, p3.Y));

                bmp.SetPixel(x, y, Color.White);
            }

            graphics.DrawImage(bmp, -offsetX, -offsetY);

            graphics.Flush();
        }
Esempio n. 28
0
        /// <summary>
        /// Function to draw the glyph character outline onto the bitmap.
        /// </summary>
        /// <param name="character">Character to write.</param>
        /// <param name="glyphBitmap">The bitmap that will receive the glyph.</param>
        /// <param name="glyphGraphics">The graphics context for the glyph bitmap.</param>
        private void DrawGlyphCharacterOutline(char character, Bitmap glyphBitmap, System.Drawing.Graphics glyphGraphics)
        {
            string charString = character.ToString(CultureInfo.CurrentCulture);

            glyphGraphics.Clear(Color.FromArgb(0));

            using (var outlineRenderer = new GraphicsPath())
            {
                outlineRenderer.AddString(charString,
                                          _fontData.Font.FontFamily,
                                          (int)_fontInfo.FontStyle,
                                          _fontData.Font.Size,
                                          new RectangleF(0, 0, glyphBitmap.Width, glyphBitmap.Height),
                                          _fontData.DrawFormat);

                // If we want an outline, then draw that first.
                if ((_fontInfo.OutlineColor1 == _fontInfo.OutlineColor2) ||
                    (_fontInfo.OutlineSize < 3))
                {
                    using (var outlinePen = new Pen(_fontInfo.OutlineColor1, _fontInfo.OutlineSize * 2))
                    {
                        outlinePen.LineJoin = LineJoin.Round;
                        glyphGraphics.DrawPath(outlinePen, outlineRenderer);
                    }
                }
                else
                {
                    GorgonColor start = _fontInfo.OutlineColor1;
                    GorgonColor end   = _fontInfo.OutlineColor2;

                    // Fade from the first to the second color via a linear function.
                    for (int i = _fontInfo.OutlineSize; i > 0; --i)
                    {
                        float delta = ((float)(i - 1) / (_fontInfo.OutlineSize - 1));

                        GorgonColor.Lerp(in start, in end, delta, out GorgonColor penColor);

                        using (var outlinePen = new Pen(penColor, i))
                        {
                            outlinePen.LineJoin = LineJoin.Round;
                            glyphGraphics.DrawPath(outlinePen, outlineRenderer);
                        }
                    }
                }
            }

            glyphGraphics.Flush();
        }
Esempio n. 29
0
        private ed.Bitmap LockEtoBitmap()
        {
            sdGraphics?.Flush();

            var sdData        = sdBuffer.LockBits(new sd.Rectangle(0, 0, sdBuffer.Width, sdBuffer.Height), sd.Imaging.ImageLockMode.ReadOnly, sdBuffer.PixelFormat);
            var bytesPerPixel = ((int)sdBuffer.PixelFormat >> 11) & 31;
            var byteLength    = sdData.Height * sdData.Width * bytesPerPixel;

            var etoBuffer = new ed.Bitmap(sdBuffer.Width, sdBuffer.Height, ed.PixelFormat.Format32bppRgba);
            var etoData   = etoBuffer.Lock();

            if (sdData.Stride < 0)
            {
                throw new Exception("Negative stride value encountered!");
            }

            unsafe
            {
                if (sdData.Stride > 0 && sdData.Stride == sdData.Width * bytesPerPixel)
                {
                    Buffer.MemoryCopy((void *)sdData.Scan0, (void *)etoData.Data, byteLength, byteLength);
                }
                else // Slightly slower route using the given stride width
                {
                    var switchColors     = MColor.ShouldSwitchColors;
                    var scan             = (byte *)sdData.Scan0;
                    var bytesPerScanLine = sdData.Width * bytesPerPixel;
                    Parallel.For(0, sdData.Height, i =>
                    {
                        var line = scan + (i * sdData.Stride);
                        for (int j = 0; j < bytesPerScanLine; j += bytesPerPixel)
                        {
                            var b = line[j];
                            var g = line[j + 1];
                            var r = line[j + 2];
                            var a = line[j + 3];
                            var c = ed.Color.FromArgb(switchColors ? b : r, g, switchColors ? r : b, a);
                            etoData.SetPixel(j / bytesPerPixel, i, c);
                        }
                    });
                }
            }

            etoData.Dispose();
            sdBuffer.UnlockBits(sdData);

            return(etoBuffer);
        }
        private void DrawTrendLine(float latestPrice)
        {
            if (double.IsNaN(latestPrice))
            {
                return;
            }

            ordinal++;

            if (ordinal > this.prices.Length - 1)
            {
                ordinal = 0;
            }
            this.prices[ordinal] = latestPrice;

            this.bitmap.Lock();

            using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height,
                                                                this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb,
                                                                this.bitmap.BackBuffer))
            {
                using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap))
                {
                    backBufferGraphics.SmoothingMode      = GDI.Drawing2D.SmoothingMode.HighSpeed;
                    backBufferGraphics.CompositingQuality = GDI.Drawing2D.CompositingQuality.HighSpeed;


                    if (ordinal == 0)
                    {
                        backBufferGraphics.Clear(GDI.Color.White);
                    }

                    for (int i = 0; i <= ordinal; i++)
                    {
                        if (ordinal > 0)
                        {
                            backBufferGraphics.DrawLine(pen,
                                                        new GDI.PointF((ordinal - 1) * dx, this.prices[ordinal - 1]),
                                                        new GDI.PointF(ordinal * dx, this.prices[ordinal]));
                        }
                    }
                    backBufferGraphics.Flush();
                }
            }
            this.bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
            this.bitmap.Unlock();
        }
        /// <summary>
        /// Get Argb
        /// </summary>
        /// <param name="sourceImage">Set source Bitmap</param>
        /// <param name="width">Set Width</param>
        /// <param name="height">Set Height</param>
        /// <returns></returns>
        public static System.Drawing.Bitmap GetArgbCopy(System.Drawing.Bitmap sourceImage, int width, int height)
        {
            System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmpNew))
            {
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                graphics.DrawImage(sourceImage, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), GraphicsUnit.Pixel);
                graphics.Flush();
            }

            return(bmpNew);
        }
Esempio n. 32
0
        public static void SetupGlide(int width, int height, int bitsPerPixel, int orientationDeg, DisplayController displayController)
        {
            Hdc = displayController.Hdc;
            LCD = new Size()
            {
                Width = width, Height = height
            };
            screen      = System.Drawing.Graphics.FromHdc(Hdc);// new (width, height);
            IsEmulator  = false;
            FitToScreen = false;

            // Show loading
            System.Drawing.Bitmap loading = Resources.GetBitmap(Resources.BitmapResources.loading);

            screen.DrawImage(loading, (LCD.Width - loading.Width) / 2, (LCD.Height - loading.Height) / 2, loading.Width, loading.Height);
            screen.Flush();
        }
Esempio n. 33
0
        private void DisposeBuffer()
        {
            if (_graphics != null)
            {
                _graphics.Flush();
                _graphics.Dispose();
                // MUST set bitmaps and graphics to null after disposal,
                // or app will occasionally crash on exit
                _graphics = null;
            }

            if (_bitmap != null)
            {
                _bitmap.Dispose();
                _bitmap = null;
            }
        }
Esempio n. 34
0
        private Bitmap resizeIfNecessary(Bitmap bmpOriginal)
        {
            if (Graphics.NPOTAllowed)
            {
                return(bmpOriginal);
            }
            else
            {
                Log.i("This hardware does not support non power-of-two textures - hax will be applied.");

                lock (resizeResultDictionary)
                {
                    // Aye, we do cache 'em...
                    if (resizeResultDictionary.Keys.Contains(bmpOriginal))
                    {
                        return(resizeResultDictionary[bmpOriginal]);
                    }
                    else
                    {
                        int referencesize = (bmpOriginal.Width > bmpOriginal.Height
                            ? bmpOriginal.Width : bmpOriginal.Height);
                        int newsize = 2;

                        // Find next bigger POT size.
                        for (int i = 1; newsize < referencesize; i++)
                        {
                            newsize = (int)Math.Round(Math.Pow(2, i));
                        }

                        potTextureSize = newsize;

                        // Resize bitmap, and return the result!
                        Bitmap bmpResult             = new Bitmap(newsize, newsize);
                        System.Drawing.Graphics gRes = System.Drawing.Graphics.FromImage(bmpResult);
                        gRes.DrawImage(bmpOriginal, 0, 0);
                        gRes.Flush(System.Drawing.Drawing2D.FlushIntention.Sync);
                        gRes.Dispose();
                        resizeResultDictionary.Add(bmpOriginal, bmpResult);
                        return(bmpResult);
                    }
                }
            }
        }
Esempio n. 35
0
		//-------------------------------------------------------------------------------------
		#region << Methods >>
		/// <summary>
		/// Осуществляет рисование в неклиенской области.
		/// </summary>
		/// <param name="g"></param>
		protected void OnNonClientPaint(Graphics g)
		{
			Rectangle r = Rectangle.Round(g.VisibleClipBounds);
			if (bStyle == BorderStyle.FixedSingle)
			{
				SolidBrush b;
				bool useVS = VisualStyleInformation.IsEnabledByUser &&
							 VisualStyleInformation.IsSupportedByOS &&
							 Application.RenderWithVisualStyles &&
							 useVisualStyle;

				if (useVS)
					b = new SolidBrush(VisualStyleInformation.TextControlBorder);
				else
					b = new SolidBrush(this.BorderColor);
				using (b)  //
				{
					g.FillRectangle(b, 0, 0, r.Width, 1);
					g.FillRectangle(b, r.Width - 1, 0, r.Width, r.Height);
					g.FillRectangle(b, 0, r.Height - 1, r.Width, r.Height);
					g.FillRectangle(b, 0, 0, 1, r.Height);
				}
			}
			else if (bStyle == BorderStyle.Fixed3D)
				switch (b3Dstyle)
				{
					case Border3DKind.Sunken:
						g.DrawLine(SystemPens.ControlDarkDark, 1, 1, r.Width - 3, 1);  // Top
						g.DrawLine(SystemPens.ControlDarkDark, 1, 1, 1, r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlLight, 1, r.Height - 2, r.Width - 2, r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlLight, r.Width - 2, 1, r.Width - 2, r.Height - 2); // Right
						goto case Border3DKind.SunkenFlat;
					case Border3DKind.SunkenFlat:
						g.DrawLine(SystemPens.ControlDark, 0, 0, r.Width - 2, 0);  // Top
						g.DrawLine(SystemPens.ControlDark, 0, 0, 0, r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlLightLight, 0, r.Height - 1, r.Width - 1, r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlLightLight, r.Width - 1, 0, r.Width - 1, r.Height - 1); // Right
						break;
					case Border3DKind.Raised:
						g.DrawLine(SystemPens.ControlLight, 0, 0, r.Width - 2, 0);  // Top
						g.DrawLine(SystemPens.ControlLight, 0, 0, 0, r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlDarkDark, 0, r.Height - 1, r.Width - 1, r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlDarkDark, r.Width - 1, 0, r.Width - 1, r.Height - 1); // Right
						g.DrawLine(SystemPens.ControlLightLight, 1, 1, r.Width - 3, 1);  // Top
						g.DrawLine(SystemPens.ControlLightLight, 1, 1, 1, r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlDark, 1, r.Height - 2, r.Width - 2, r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.Width - 2, 1, r.Width - 2, r.Height - 2); // Right
						break;
					case Border3DKind.RaisedFlat:
						g.DrawLine(SystemPens.ControlLightLight, 0, 0, r.Width - 2, 0);  // Top
						g.DrawLine(SystemPens.ControlLightLight, 0, 0, 0, r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlDark, 0, r.Height - 1, r.Width - 1, r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.Width - 1, 0, r.Width - 1, r.Height - 1); // Right
						break;
					case Border3DKind.Etched:
						g.DrawLine(SystemPens.ControlDark, 0, 0, r.Width - 2, 0);  // Top
						g.DrawLine(SystemPens.ControlDark, 0, 0, 0, r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlLightLight, 0, r.Height - 1, r.Width - 1, r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlLightLight, r.Width - 1, 0, r.Width - 1, r.Height - 1); // Right
						g.DrawLine(SystemPens.ControlLightLight, 1, 1, r.Width - 3, 1);  // Top
						g.DrawLine(SystemPens.ControlLightLight, 1, 1, 1, r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlDark, 1, r.Height - 2, r.Width - 2, r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.Width - 2, 1, r.Width - 2, r.Height - 2); // Right
						break;
					case Border3DKind.Bump:
						g.DrawLine(SystemPens.ControlLightLight, 0, 0, r.Width - 2, 0);  // Top
						g.DrawLine(SystemPens.ControlLightLight, 0, 0, 0, r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlDark, 0, r.Height - 1, r.Width - 1, r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.Width - 1, 0, r.Width - 1, r.Height - 1); // Right
						g.DrawLine(SystemPens.ControlDark, 1, 1, r.Width - 3, 1);  // Top
						g.DrawLine(SystemPens.ControlDark, 1, 1, 1, r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlLightLight, 1, r.Height - 2, r.Width - 2, r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlLightLight, r.Width - 2, 1, r.Width - 2, r.Height - 2); // Right
						break;
				}
			g.Flush();
		}
Esempio n. 36
0
        /// <summary>
        /// 
        /// </summary>
        internal void SetText()
        {
            if (!imageList.Images.ContainsKey(text))
                return;
            if (editBox.Handle == IntPtr.Zero)
                return;

            icon = imageList.Images[text];
            // Set Text.
            gfx = System.Drawing.Graphics.FromHwnd(editBox.Handle);
            gfx.Clear(this.BackColor);
            gfx.DrawImage(icon, 0, 0);
            Brush brush = new SolidBrush(this.ForeColor);
            gfx.DrawString(text, this.Font, brush, icon.Width + 2, 0);
            gfx.Flush();
        }
Esempio n. 37
0
        private void CycleDrawArea()
        {
            g = this.CreateGraphics();
            g.ResetClip();

            SolidBrush myBrush = new SolidBrush(Color.SteelBlue);
            g.FillRectangle(myBrush, 23, 43, 589, 184);

            // background
            if ((inPort) && (portBmp != null))
            {
                g.DrawImage(portBmp, new RectangleF(new PointF(23, 43), new SizeF(589, 184)));
            }
            else if ((water1Bmp != null) && (water2Bmp != null))
            {
                if (waterSwitch)
                {
                    g.DrawImage(water1Bmp, new RectangleF(new PointF(23, 43), new SizeF(589, 184)));
                }
                else
                {
                    g.DrawImage(water2Bmp, new RectangleF(new PointF(23, 43), new SizeF(589, 184)));
                }
            }

            if (inPort) // draw ship docked at port
            {
                if (shipBmpArr[Player.CurrentShip.ID - 1] != null)
                {
                    g.DrawImage(shipBmpArr[Player.CurrentShip.ID - 1], new RectangleF(new PointF(188, 54), new SizeF(261, 123)));
                }
            }
            else  // draw player ship and enemy
            {
                if (shipBmpArr[Player.CurrentShip.ID - 1] != null)
                {
                    if (Player.CurrentShip.HP > 0)
                    {
                        // Player still alive, draw ship
                        g.DrawImage(shipBmpArr[Player.CurrentShip.ID - 1], new RectangleF(new PointF(40, 71), new SizeF(261, 123)));
                    }
                    else
                    {
                        AddStatusLine("Player dead");
                        // draw the blood pool, if available
                        if (bloodBmp != null)
                        {
                            AddStatusLine("drawing blood bmp");
                            g.DrawImage(bloodBmp, new RectangleF(new PointF(40, 71), new SizeF(261, 123)));
                        }
                    }

                }
                if ((CurrentEnemy != null) && (CurrentEnemy.ID >= 0))
                {
                    if ((fishBmpArr[CurrentEnemy.ID - 1] != null) && (inCombat && !isDead))
                    {
                        g.DrawImage(fishBmpArr[CurrentEnemy.ID - 1], new RectangleF(new PointF(317, 43), new SizeF(294, 184)));
                    }
                }
            }

            g.Flush();
            g.Dispose();
        }
Esempio n. 38
0
		//-------------------------------------------------------------------------------------
		/// <summary>
		/// ќсуществл¤ет рисование в неклиенской области.
		/// </summary>
		/// <param name="g"></param>
		protected void OnNonClientPaint(Graphics g)
		{
			bool useVS = VisualStyleInformation.IsEnabledByUser &&
																										VisualStyleInformation.IsSupportedByOS &&
																										Application.RenderWithVisualStyles &&
																										useVisualStyleBorderColor;


			Rectangle r = Rectangle.Round(g.VisibleClipBounds);
			if(borderStyle == BorderStyle.FixedSingle)
			{
				SolidBrush b;
				if(useVS)
					b = new SolidBrush(VisualStyleInformation.TextControlBorder);
				else
					b = new SolidBrush(this.BorderColor);
				using(b)  //
				{
					g.FillRectangle(b, 0, 0, r.Width, borderWidth.Top);
					g.FillRectangle(b, r.Width - borderWidth.Right, 0, r.Width, r.Height);
					g.FillRectangle(b, 0, r.Height - borderWidth.Bottom, r.Width, r.Height);
					g.FillRectangle(b, 0, 0, borderWidth.Left, r.Height);
				}
			}
			else if(borderStyle == BorderStyle.Fixed3D)
			{
				g.DrawLine(SystemPens.ControlDarkDark, 1, 1, r.Width - 3, 1);  // Top
				g.DrawLine(SystemPens.ControlDarkDark, 1, 1, 1, r.Height - 3); // Left
				g.DrawLine(SystemPens.ControlLight, 1, r.Height - 2, r.Width - 2, r.Height - 2); // Bottom
				g.DrawLine(SystemPens.ControlLight, r.Width - 2, 1, r.Width - 2, r.Height - 2); // Right
				g.DrawLine(SystemPens.ControlDark, 0, 0, r.Width - 2, 0);  // Top
				g.DrawLine(SystemPens.ControlDark, 0, 0, 0, r.Height - 2); // Left
				g.DrawLine(SystemPens.ControlLightLight, 0, r.Height - 1, r.Width - 1, r.Height - 1); // Bottom
				g.DrawLine(SystemPens.ControlLightLight, r.Width - 1, 0, r.Width - 1, r.Height - 1); // Right
			}
			g.Flush();
		}
Esempio n. 39
0
        //, int Alpha)
        public void makeLayer(String RedDataSetName, String GreenDataSetName, String BlueDataSetName)
        {
            //blue only
            ViewArea = Control.ViewArea;
            //int x = (int)Control.FromLatLngToLocal(ViewArea.LocationRightBottom).X;
            curLayer = new Bitmap((int)Control.FromLatLngToLocal(ViewArea.LocationRightBottom).X,(int) Control.FromLatLngToLocal(ViewArea.LocationRightBottom).Y);
            g = System.Drawing.Graphics.FromImage(curLayer);
            //g.Clear(Color.Black);
            //
            allPoints = GDSM.DataSets[BlueDataSetName];
            Console.WriteLine(BlueDataSetName + GDSM.DataSets.ContainsKey(BlueDataSetName));

            activePoints = activeData(allPoints, ViewArea, BlueDataSetName);
            GPoint TL;
            GPoint BR;
            foreach (GridDataPoint p in activePoints.points)
            {
                TL = Control.FromLatLngToLocal(p.loc.LocationTopLeft);
                BR = Control.FromLatLngToLocal(p.loc.LocationRightBottom);
                //Console.WriteLine("Drawing: [" + TL.X + ", " + TL.Y + "] [" + BR.X + ", " + BR.Y + "] - " + p.value + " - (" + p.loc.LocationRightBottom.Lat + ", " + p.loc.LocationRightBottom.Lng +")");
                g.FillRectangle(new SolidBrush(Color.FromArgb(125, Color.FromArgb(0,0,p.value))),new Rectangle((int)TL.X, (int)TL.Y, (int)(BR.X - TL.X), (int)(BR.Y - TL.Y)));
            }

            g.Flush();
            Layers.Add(curLayer);
        }
Esempio n. 40
0
		//-------------------------------------------------------------------------------------
		#region << Methods >>
		/// <summary>
		/// Осуществляет рисование в неклиенской области.
		/// </summary>
		/// <param name="g"></param>
		protected void OnNonClientPaint(Graphics g)
		{
			Rectangle r = Rectangle.Round(g.VisibleClipBounds);
			Padding pd;
			if(borderStyle == System.Windows.Forms.BorderStyle.None)
				pd = Margin;
			else if(borderStyle == System.Windows.Forms.BorderStyle.FixedSingle)
				pd = Padding.Add(Margin, borderWidth);
			else if(b3Dstyle == Border3DKind.RaisedFlat || b3Dstyle == Border3DKind.SunkenFlat)
				pd = Padding.Add(Margin, new Padding(1));
			else
				pd = Padding.Add(Margin, new Padding(2));

			if(pd.All != 0)
				if(Parent == null || Parent is SimPanel == false)
				{
					Color c = Parent == null ? BackColor : Parent.BackColor;
					if(c == Color.Transparent)
					{
						Control p = Parent;
						while(p != null)
						{
							c = p.BackColor;
							if(c != Color.Transparent)
								break;
							p = p.Parent;
						} 
						if(c == Color.Transparent)
							c = SystemColors.Control;
					} 
					using(SolidBrush b = new SolidBrush(c))
					{
						g.FillRectangle(b, 0, 0, r.Width, pd.Top);
						g.FillRectangle(b, r.Width - pd.Right, 0, pd.Right, r.Height);
						g.FillRectangle(b, 0, r.Height - pd.Bottom, r.Width, pd.Bottom);
						g.FillRectangle(b, 0, 0, pd.Left, r.Height);
					}
				}
				else
				{
					Rectangle rr = new Rectangle(0, 0, r.Width, pd.Top);
					if(rr.Width > 0 && rr.Height > 0)
						WinFormsUtils.CallPaint(Parent, new PaintEventArgs(g, rr) );

					rr = new Rectangle(r.Width - pd.Right, 0, pd.Right, r.Height);
					if(rr.Width > 0 && rr.Height > 0)
						WinFormsUtils.CallPaint(Parent, new PaintEventArgs(g, rr));

					rr = new Rectangle(0, r.Height - pd.Bottom, r.Width, pd.Bottom);
					if(rr.Width > 0 && rr.Height > 0)
						WinFormsUtils.CallPaint(Parent, new PaintEventArgs(g, rr));

					rr = new Rectangle(0, 0, pd.Left, r.Height);
					if(rr.Width > 0 && rr.Height > 0)
						WinFormsUtils.CallPaint(Parent, new PaintEventArgs(g, rr));
				}


			if(borderStyle != System.Windows.Forms.BorderStyle.None)
			{
				r.X += Margin.Left;
				r.Width -= Margin.Horizontal;
				r.Y += Margin.Top;
				r.Height -= Margin.Vertical;
			}

			if(borderStyle == BorderStyle.FixedSingle)
			{
				bool useVS = VisualStyleInformation.IsEnabledByUser && 
																	VisualStyleInformation.IsSupportedByOS &&
																	Application.RenderWithVisualStyles &&
																	useVisualStyleBorderColor;


				SolidBrush b;
				if(useVS)
					b = new SolidBrush(VisualStyleInformation.TextControlBorder);
				else
					b = new SolidBrush(this.BorderColor);
				using(b)  //
				{
					//g.FillRectangle(Brushes.Red, 0, 0, r.Width, r.Height);
					g.FillRectangle(b, r.X, r.Y, r.Width, borderWidth.Top);
					g.FillRectangle(b, r.X + r.Width - borderWidth.Right, r.Y, borderWidth.Right, r.Height);
					g.FillRectangle(b, r.X, r.Y + r.Height - borderWidth.Bottom, r.Width, borderWidth.Bottom);
					g.FillRectangle(b, r.X, r.Y, borderWidth.Left, r.Height);
				}
			}
			else if(borderStyle == BorderStyle.Fixed3D)
			{
				switch(b3Dstyle)
				{
					case Border3DKind.Sunken:
						g.DrawLine(SystemPens.ControlDarkDark, r.X+1, r.Y+1, r.Width, r.Y+1);  // Top
						g.DrawLine(SystemPens.ControlDarkDark, r.X+1, r.Y+1, r.X+1, r.Height); // Left
						g.DrawLine(SystemPens.ControlLight, r.X+1, r.Y + r.Height - 2, r.Width, r.Y + r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlLight, r.X + r.Width - 2, r.Y+1, r.X + r.Width - 2, r.Height - 1); // Right
						goto case Border3DKind.SunkenFlat;
					case Border3DKind.SunkenFlat:
						g.DrawLine(SystemPens.ControlDark, r.X, r.Y, r.Width, r.Y);  // Top
						g.DrawLine(SystemPens.ControlDark, r.X, r.Y, r.X, r.Y + r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlLightLight, r.X, r.Y + r.Height - 1, r.Width + 1, r.Y + r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlLightLight, r.X + r.Width - 1, r.Y, r.X + r.Width - 1, r.Height); // Right
						break;
					case Border3DKind.Raised:
						g.DrawLine(SystemPens.ControlLight, r.X, r.Y, r.X + r.Width - 2, r.Y);  // Top
						g.DrawLine(SystemPens.ControlLight, r.X, r.Y, r.X, r.Y + r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlDarkDark, r.X, r.Y + r.Height - 1, r.X + r.Width - 1, r.Y + r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlDarkDark, r.X + r.Width - 1, r.Y, r.X + r.Width - 1, r.Y + r.Height - 1); // Right
						g.DrawLine(SystemPens.ControlLightLight, r.X + 1, r.Y + 1, r.X + r.Width - 3, r.Y + 1);  // Top
						g.DrawLine(SystemPens.ControlLightLight, r.X + 1, r.Y + 1, r.X + 1, r.Y + r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlDark, r.X + 1, r.Y + r.Height - 2, r.X + r.Width - 2, r.Y + r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.X + r.Width - 2, r.Y + 1, r.X + r.Width - 2, r.Y + r.Height - 2); // Right
						break;
					case Border3DKind.RaisedFlat:
						g.DrawLine(SystemPens.ControlLightLight, r.X, r.Y, r.X + r.Width - 2, r.Y);  // Top
						g.DrawLine(SystemPens.ControlLightLight, r.X, r.Y, r.X, r.Y + r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlDark, r.X, r.Y + r.Height - 1, r.X + r.Width - 1,r.Y +  r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.X + r.Width - 1, r.Y, r.X + r.Width - 1, r.Y + r.Height - 1); // Right
						break;
					case Border3DKind.Etched:
						g.DrawLine(SystemPens.ControlDark,       r.X, r.Y, r.X + r.Width - 2, r.Y);  // Top
						g.DrawLine(SystemPens.ControlDark,       r.X, r.Y, r.X, r.Y + r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlLightLight, r.X, r.Y + r.Height - 1, r.X + r.Width - 1, r.Y + r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlLightLight, r.X + r.Width - 1, r.Y, r.X + r.Width - 1, r.Y + r.Height - 1); // Right
						g.DrawLine(SystemPens.ControlLightLight, r.X + 1, r.Y + 1, r.X + r.Width - 3, r.Y + 1);  // Top
						g.DrawLine(SystemPens.ControlLightLight, r.X + 1, r.Y + 1, r.X + 1, r.Y + r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlDark, r.X + 1, r.Y + r.Height - 2, r.X + r.Width - 2, r.Y + r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlDark, r.X + r.Width - 2, r.Y + 1, r.X + r.Width - 2, r.Y + r.Height - 2); // Right
						break;
					case Border3DKind.Bump:
						g.DrawLine(SystemPens.ControlLightLight, r.X, r.Y, r.X + r.Width - 2, r.Y);  // Top
						g.DrawLine(SystemPens.ControlLightLight, r.X, r.Y, r.X, r.Y + r.Height - 2); // Left
						g.DrawLine(SystemPens.ControlDark,       r.X, r.Y + r.Height - 1, r.X + r.Width - 1, r.Y + r.Height - 1); // Bottom
						g.DrawLine(SystemPens.ControlDark,       r.X + r.Width - 1, r.Y, r.X + r.Width - 1, r.Y + r.Height - 1); // Right
						g.DrawLine(SystemPens.ControlDark,       r.X + 1, r.Y + 1, r.X + r.Width - 3, r.Y + 1);  // Top
						g.DrawLine(SystemPens.ControlDark,       r.X + 1, r.Y + 1, r.X + 1, r.Y + r.Height - 3); // Left
						g.DrawLine(SystemPens.ControlLightLight, r.X + 1, r.Y + r.Height - 2, r.X + r.Width - 2, r.Y + r.Height - 2); // Bottom
						g.DrawLine(SystemPens.ControlLightLight, r.X + r.Width - 2, r.Y + 1, r.X + r.Width - 2, r.Y + r.Height - 2); // Right
						break;
				}
			}
			g.Flush(); 
		}
        private static CharacterGlyph ImportCharacter(char character, Font font, Bitmap stagingBitmap, Graphics stagingGraphics)
        {
            var str = character.ToString();
            var characterSize = stagingGraphics.MeasureString(str, font, Point.Empty, NoFontFallbackFormat);
            var abcSpacing = CalculateABCSpacing(character, font, stagingGraphics);

            uint width = (uint)Math.Ceiling(abcSpacing.A + abcSpacing.B + abcSpacing.C);
            uint height = (uint)Math.Ceiling(characterSize.Height);
            Debug.Assert(width <= BitmapSize && height < BitmapSize);

            stagingGraphics.Clear(Color.Black);
            stagingGraphics.DrawString(str, font, ForegroundBrush, 0, 0, NoFontFallbackFormat);
            stagingGraphics.Flush();

            var characterBitmap = stagingBitmap.Clone(new Rectangle(0, 0, (int)width, (int)height), PixelFormat.Format32bppArgb);

            return new CharacterGlyph(character, characterBitmap, width, height);
        }
Esempio n. 42
0
        public void Draw( Graphics g, Rectangle rectClient )
        {
            Brush brushBack     = new SolidBrush( BackColor );
            Brush brushAddress  = new SolidBrush( Color.Black );
            Brush brushBytes    = new SolidBrush( Color.Blue );
            Brush brushChars    = new SolidBrush( Color.DarkGreen );

            Font fontText = new Font( this.Font.FontFamily, this.Font.Size, FontStyle.Regular );

            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Near;
            format.LineAlignment = StringAlignment.Near;

            //  Wipe the whole background.
            g.FillRectangle( brushBack, rectClient );
            int offset = 0;
            float X = AutoScrollPosition.X + padding;
            float Y = AutoScrollPosition.Y + padding;

            if( document != null )
            {
                do
                {
                    if( Y + sizeAddress.Height > 0 )
                    {
                        g.DrawString( offset.ToString( "X6" ), fontText, brushAddress, X, Y, format );

                        int limit = Math.Min( offset + nCols, document.Data.Length );

                        int b = offset;
                        X += sizeAddress.Width;
                        do
                        {
                            X += sizeAddress.Width / 2;
                            g.DrawString( document.Data[ b++ ].ToString( "X2" ), fontText, brushBytes, X, Y, format );
                        } while( b < limit );

                        b = offset;
                        X += sizeAddress.Width / 2;
                        do
                        {
                            char ch = (char) document.Data[ b++ ];
                            if( ch > 32 && ch < 128 )
                            {
                                g.DrawString( ch.ToString(), fontText, brushBytes, X, Y, format );
                            }
                            X += sizeAddress.Width / 6;
                        } while( b < limit );
                    }

                    offset += nCols;
                    Y += sizeAddress.Height;
                    X = AutoScrollPosition.X + padding;
                } while( offset < document.Data.Length );
            }

            g.Flush();
        }
        /// <summary>
        /// This method takes the actual capture of the document (frame)
        /// </summary>
        /// <param name="frameDocument"></param>
        /// <param name="contentWindowDetails">Needed for referencing the location of the frame</param>
        /// <returns>Bitmap with the capture</returns>
        private static void drawDocument(DocumentContainer documentContainer, WindowDetails contentWindowDetails, Graphics graphicsTarget)
        {
            documentContainer.setAttribute("scroll", 1);

            //Get Browser Window Width & Height
            int pageWidth = documentContainer.ScrollWidth;
            int pageHeight = documentContainer.ScrollHeight;
            if (pageWidth * pageHeight == 0) {
                LOG.WarnFormat("Empty page for DocumentContainer {0}: {1}", documentContainer.Name, documentContainer.Url);
                return;
            }

            //Get Screen Width & Height (this is better as the WindowDetails.ClientRectangle as the real visible parts are there!
            int viewportWidth = documentContainer.ClientWidth;
            int viewportHeight = documentContainer.ClientHeight;
            if (viewportWidth * viewportHeight == 0) {
                LOG.WarnFormat("Empty viewport for DocumentContainer {0}: {1}", documentContainer.Name, documentContainer.Url);
                return;
            }

            // Store the current location so we can set the browser back and use it for the mouse cursor
            int startLeft = documentContainer.ScrollLeft;
            int startTop = documentContainer.ScrollTop;

            LOG.DebugFormat("Capturing {4} with total size {0},{1} displayed with size {2},{3}", pageWidth, pageHeight, viewportWidth, viewportHeight, documentContainer.Name);

            // Variable used for looping horizontally
            int horizontalPage = 0;

            // The location of the browser, used as the destination into the bitmap target
            Point targetOffset = new Point();

            // Loop of the pages and make a copy of the visible viewport
            while ((horizontalPage * viewportWidth) < pageWidth) {
                // Scroll to location
                documentContainer.ScrollLeft = viewportWidth * horizontalPage;
                targetOffset.X = documentContainer.ScrollLeft;

                // Variable used for looping vertically
                int verticalPage = 0;
                while ((verticalPage * viewportHeight) < pageHeight) {
                    // Scroll to location
                    documentContainer.ScrollTop = viewportHeight * verticalPage;
                    //Shoot visible window
                    targetOffset.Y  = documentContainer.ScrollTop;

                    // Draw the captured fragment to the target, but "crop" the scrollbars etc while capturing
                    Size viewPortSize = new Size(viewportWidth, viewportHeight);
                    Rectangle clientRectangle = new Rectangle(documentContainer.SourceLocation, viewPortSize);
                    Image fragment = contentWindowDetails.PrintWindow();
                    if (fragment != null) {
                        LOG.DebugFormat("Captured fragment size: {0}x{1}", fragment.Width, fragment.Height);
                        try {
                            // cut all junk, due to IE "border" we need to remove some parts
                            Rectangle viewportRect = documentContainer.ViewportRectangle;
                            if (!viewportRect.IsEmpty) {
                                LOG.DebugFormat("Cropping to viewport: {0}", viewportRect);
                                ImageHelper.Crop(ref fragment, ref viewportRect);
                            }
                            LOG.DebugFormat("Cropping to clientRectangle: {0}", clientRectangle);
                            // Crop to clientRectangle
                            if (ImageHelper.Crop(ref fragment, ref clientRectangle)) {
                                Point targetLocation = new Point(documentContainer.DestinationLocation.X, documentContainer.DestinationLocation.Y);
                                LOG.DebugFormat("Fragment targetLocation is {0}", targetLocation);
                                targetLocation.Offset(targetOffset);
                                LOG.DebugFormat("After offsetting the fragment targetLocation is {0}", targetLocation);
                                LOG.DebugFormat("Drawing fragment of size {0} to {1}", fragment.Size, targetLocation);
                                graphicsTarget.DrawImage(fragment, targetLocation);
                                graphicsTarget.Flush();
                            } else {
                                // somehow we are capturing nothing!?
                                LOG.WarnFormat("Crop of {0} failed?", documentContainer.Name);
                                break;
                            }
                        } finally {
                            fragment.Dispose();
                        }
                    } else {
                        LOG.WarnFormat("Capture of {0} failed!", documentContainer.Name);
                    }
                    verticalPage++;
                }
                horizontalPage++;
            }
            // Return to where we were
            documentContainer.ScrollLeft = startLeft;
            documentContainer.ScrollTop = startTop;
        }
Esempio n. 44
0
  //-------------------------------------------------------------------------------------
  /// <summary>
  /// Осуществляет рисование в неклиенской области.
  /// </summary>
  /// <param name="g"></param>
  protected void OnNonClientPaint(Graphics g)
  {
   bool useVS = System.Windows.Forms.VisualStyles.VisualStyleInformation.IsEnabledByUser && 
                System.Windows.Forms.VisualStyles.VisualStyleInformation.IsSupportedByOS &&
                 Application.RenderWithVisualStyles &&
                 useVisualStyleBorderColor;


   Rectangle r = Rectangle.Round(g.VisibleClipBounds);
   SolidBrush b;
   if(useVS)
    b = new SolidBrush(System.Windows.Forms.VisualStyles.VisualStyleInformation.TextControlBorder);
   else
    b = new SolidBrush(this.BorderColor);
   using(b)  //
   {
    g.FillRectangle(b, 0, 0, r.Width, 1);
    g.FillRectangle(b, r.Width - 1, 0, r.Width, r.Height);
    g.FillRectangle(b, 0, r.Height - 1, r.Width, r.Height);
    g.FillRectangle(b, 0, 0, 1, r.Height);
   }
   g.Flush();
  }
Esempio n. 45
0
        /// <summary>
        /// The draw debug method for <see cref="Engine"/>
        /// </summary>
        /// <param name="g">
        /// The <see cref="Graphics"/> for the Draw Debug method..
        /// </param>
        public void DrawDebug(Graphics g)
        {
            g.DrawString(
                string.Format("FPS: {0}", this.engine.CurrentFPS),
                new Font("Serif", 12, FontStyle.Bold),
                Brushes.Aqua,
                new PointF(5, 5));

            g.FillEllipse(
                this.environment.Players[0].IsActionPressed(
                    new Core.Players.Actions.KeyMapping { Action = Core.Players.Actions.KeyMapping.KeyAction.JUMP })
                    ? Brushes.Aquamarine
                    : Brushes.Red,
                new Rectangle(50, 60, 8, 8));

            g.FillRectangle(
                this.environment.Players[0].IsActionPressed(
                    new Core.Players.Actions.KeyMapping { Action = Core.Players.Actions.KeyMapping.KeyAction.UP })
                    ? Brushes.Aquamarine
                    : Brushes.Red,
                new Rectangle(50, 80, 8, 15));

            g.FillRectangle(
                this.environment.Players[0].IsActionPressed(
                    new Core.Players.Actions.KeyMapping { Action = Core.Players.Actions.KeyMapping.KeyAction.DOWN })
                    ? Brushes.Aquamarine
                    : Brushes.Red,
                new Rectangle(50, 100, 8, 15));

            g.FillRectangle(
                this.environment.Players[0].IsActionPressed(
                    new Core.Players.Actions.KeyMapping { Action = Core.Players.Actions.KeyMapping.KeyAction.RIGHT })
                    ? Brushes.Aquamarine
                    : Brushes.Red,
                new Rectangle(61, 93, 15, 8));

            g.FillRectangle(
                this.environment.Players[0].IsActionPressed(
                    new Core.Players.Actions.KeyMapping { Action = Core.Players.Actions.KeyMapping.KeyAction.LEFT })
                    ? Brushes.Aquamarine
                    : Brushes.Red,
                new Rectangle(32, 93, 15, 8));

            g.Flush();
        }
Esempio n. 46
0
 protected void saveImage(Graphics g,Bitmap bmp,TileAddress tile,int level)
 {
     g.Flush();
     string filename=Path.Combine(tileDir,string.Format("{0}\\{1}\\{2}.png",level,tile.X,tile.Y));
     Directory.CreateDirectory(Path.GetDirectoryName(filename));
     bmp.Save(filename);
 }
Esempio n. 47
0
        /// <summary>
        /// Creates a Bitmap Image.
        /// </summary>
        /// <returns> Bitmap image.</returns>
        public Bitmap DrawImage()
        {
            // Create the bmpImage again with the correct size for the text and font.
            _objBmpImage = new Bitmap(_objBmpImage, new Size(ImageWidth.Value, ImageHeight.Value));
            // Add the colors to the new bitmap.
            _objGraphics = Graphics.FromImage(_objBmpImage);
            _objRectangle = new Rectangle(new Point(0, 0), new Size(ImageWidth.Value - 1, ImageHeight.Value - 1));
            _objGraphics.DrawString(Text, TextFont, new SolidBrush(TextColor.Value), _objRectangle, _stringFormat);

            if (IsBorderRequired)
            {
                _objGraphics.DrawRectangle(this.BorderColor, _objRectangle);
            }
            _objGraphics.Flush();

            return (_objBmpImage);
        }
Esempio n. 48
0
    public static Bitmap FromBundle(IBundle bundle, Graphics g) {
      // The entities will be drawn to our graphics surface using
      // their locations on the canvas.  We want them to be drawn
      // relative to the 0,0 (upper, left corner) of our image.
      // Therefore, calculate the offset required to position them
      // (normalize) in our image and apply that translation to
      // g2, the GDI+ drawing surface used to paint the entities to
      // the image.  Notice we're actually calculating the offset
      // relative to location 5,5.  We adjusting the image height
      // and widht by 10 to ensure we catch everything, so by using
      // location 5,5 here we kept things centered.
      Point offset = new Point(
          5 - bundle.Rectangle.X,
          5 - bundle.Rectangle.Y);
      Matrix matrix = new Matrix();
      matrix.Translate(offset.X, offset.Y);

      Rectangle bundleArea = bundle.Rectangle;
      // bundleArea.Inflate(5, 5);

      Bitmap image = new Bitmap(
          bundleArea.Width + 10,
          bundleArea.Height + 10,
          g);
      Graphics g2 = Graphics.FromImage(image);
      g2.Transform = matrix;


      // The background color is a weird blue, so I'm filling the
      // entire area first with a white color to get around this.
      g2.Clear(Color.White);
      g2.SmoothingMode = SmoothingMode.HighQuality;
      g2.CompositingQuality = CompositingQuality.HighQuality;
      g2.InterpolationMode = InterpolationMode.HighQualityBicubic;

      // Deselect and set Hovered to 'false' for all entities so 
      // they're drawn to the image in their *normal* state.
      bundle.DeSelectAll();
      bundle.SetHovered(false);
      bundle.Paint(g2);

      g.Flush();
      g2.Flush();
      g.Dispose();
      g2.Dispose();

      //System.IntPtr dc1 = g.GetHdc();

      //System.IntPtr dc2 = g2.GetHdc();

      //BitBlt(dc2, 0, 0, width, height, dc1, 0, 0, 0x00CC0020);

      //g.ReleaseHdc(dc1);

      //g2.ReleaseHdc(dc2);

      //g.Dispose();

      //g2.Dispose();
      return image;
    }
Esempio n. 49
0
        // Rasterizes a single character glyph.
        static Glyph ImportGlyph(char character, Font font, Brush brush, StringFormat stringFormat, Bitmap bitmap, Graphics graphics)
        {
            string characterString = character.ToString();

            // Measure the size of this character.
            SizeF size = graphics.MeasureString(characterString, font, Point.Empty, stringFormat);

            int characterWidth = (int)Math.Ceiling(size.Width);
            int characterHeight = (int)Math.Ceiling(size.Height);

            // Pad to make sure we capture any overhangs (negative ABC spacing, etc.)
            int padWidth = characterWidth;
            int padHeight = characterHeight / 2;

            int bitmapWidth = characterWidth + padWidth * 2;
            int bitmapHeight = characterHeight + padHeight * 2;

            if (bitmapWidth > MaxGlyphSize || bitmapHeight > MaxGlyphSize)
                throw new Exception("Excessively large glyph won't fit in my lazily implemented fixed size temp surface.");

            // Render the character.
            graphics.Clear(Color.Black);
            graphics.DrawString(characterString, font, brush, padWidth, padHeight, stringFormat);
            graphics.Flush();

            // Clone the newly rendered image.
            Bitmap glyphBitmap = bitmap.Clone(new Rectangle(0, 0, bitmapWidth, bitmapHeight), PixelFormat.Format32bppArgb);

            BitmapUtils.ConvertGreyToAlpha(glyphBitmap);

            // Query its ABC spacing.
            float? abc = GetCharacterWidth(character, font, graphics);

            // Construct the output Glyph object.
            return new Glyph(character, glyphBitmap)
            {
                XOffset = -padWidth,
                XAdvance = abc.HasValue ? padWidth - bitmapWidth + abc.Value : -padWidth,
                YOffset = -padHeight,
            };
        }
Esempio n. 50
0
        private void draw_invalidData()
        {
            drawBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            g = Graphics.FromImage(drawBitmap);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            g.DrawString("Invalid Data", new Font("Tahoma", 60), Brushes.Black, 0, 0);
            g.Flush();
            pictureBox1.Image = drawBitmap;
            pictureBox1.Image.Tag = "jhn";
        }
Esempio n. 51
0
        public static bool OverLayBitmapToFormNewImage(Bitmap to_be_overlaid, Graphics graphics)
        {
            try
            {
                if (to_be_overlaid == null || graphics == null)
                {
                    throw new ArgumentNullException();
                }

                graphics.DrawImageUnscaled(to_be_overlaid, new Point(0, 0));
                graphics.Flush();
                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
Esempio n. 52
0
        /// <summary>
        /// Implementation of the IPainter RenderAll method
        /// </summary>
        /// <param name="g">Target Graphics object</param>
        public void RenderAll(Graphics g)
        {
            try
            {
                Control.InitVars();
                Control.InitScrollbars();
                SetBrackets();
                SetSpanIndicators();
                int j = Control.View.FirstVisibleRow;

                int diff = j - LastRow;
                LastRow = j;
                if (Control.SmoothScroll)
                {
                    if (diff == 1)
                    {
                        for (int i = Control.View.RowHeight; i > 0; i -= Control.SmoothScrollSpeed)
                        {
                            yOffset = i + Control.View.YOffset;
                            RenderAll2();
                            g.Flush();
                            Thread.Sleep(0);
                        }
                    }
                    else if (diff == -1)
                    {
                        for (int i = -Control.View.RowHeight; i < 0; i += Control.SmoothScrollSpeed)
                        {
                            yOffset = i + Control.View.YOffset;
                            RenderAll2();
                            g.Flush();
                            Thread.Sleep(0);
                        }
                    }
                }

                yOffset = Control.View.YOffset;
                RenderAll2();
                //g.Flush ();
                //System.Threading.Thread.Sleep (0);
            }
            catch {}
        }
Esempio n. 53
0
        private void GameForm_Paint(object sender, PaintEventArgs e)
        {
            g = e.Graphics;
            Pen myPen = new Pen(Color.Gray);
            SolidBrush myBrush = new SolidBrush(Color.Black);
            g.FillRectangle(myBrush, 20, 40, 595, 190);
            g.DrawRectangle(myPen, 22, 42, 590, 185);
            myBrush.Color = Color.SteelBlue;
            g.FillRectangle(myBrush, 23, 43, 589, 184);

            // draw the splash screen
            if (!gameStarted)
            {
                myBrush.Color = Color.DarkKhaki;
                RectangleF rect = new RectangleF(new PointF(30, 60), new SizeF(350, 60));
                g.DrawString("Commercial Angler", new Font("Arial", 26), myBrush, rect, new StringFormat(StringFormatFlags.NoWrap));
                myBrush.Color = Color.DarkGray;
                rect = new RectangleF(new PointF(268, 105), new SizeF(65, 15));
                g.DrawString("Version 0.1", new Font("Arial", 8), myBrush, rect, new StringFormat(StringFormatFlags.NoWrap));
                myBrush.Color = Color.Black;
                rect = new RectangleF(new PointF(490, 205), new SizeF(205, 15));
                g.DrawString("©2007 Bruce C. Miller", new Font("Arial", 8), myBrush, rect, new StringFormat(StringFormatFlags.NoWrap));

                // ship img
                g.DrawImage(shipBmpArr[16], new RectangleF(new PointF(334, 71), new SizeF(261, 123)));
                g.Flush();
                g.Dispose();
            }
            else
            {
                CycleDrawArea();
            }
        }
Esempio n. 54
0
		/// <summary>
		/// Whenever the textbox is repainted, we have to draw the image.
		/// </summary>
		public void DrawImage()
		{
			if((CurrentIcon!=null))
			{	
				// Gets a GDI drawing surface from the textbox.
				gfx = Graphics.FromHwnd (this.Handle);
				bool rightToLeft = false;
				if(Owner.RightToLeft == RightToLeft.Inherit)
				{
					if(Owner.Parent.RightToLeft == RightToLeft.Yes)
						rightToLeft =  true;

				}
				if(Owner.RightToLeft == RightToLeft.Yes || rightToLeft)
				{
					gfx.DrawImage(CurrentIcon,gfx.VisibleClipBounds.Width - CurrentIcon.Width,0);
				}
				else if(Owner.RightToLeft == RightToLeft.No || rightToLeft)
					gfx.DrawImage(CurrentIcon,0,0);
				
				gfx.Flush();
				gfx.Dispose();
			}
		}
Esempio n. 55
0
 protected void saveImage(Graphics g, Bitmap bmp, string quadKey)
 {
     g.Flush();
     var level = quadKey.Length;
     var tile = merc.QuadTreeToTile(quadKey, level);
     string filename = Path.Combine(tileDir, string.Format("{0}\\{1}\\{2}.png", level, tile.X, tile.Y));
     Directory.CreateDirectory(Path.GetDirectoryName(filename));
     bmp.Save(filename);
 }
Esempio n. 56
0
        /// <summary>
        /// Implementation of the IPainter RenderAll method
        /// </summary>
        /// <param name="g">Target Graphics object</param>
        public void RenderAll(Graphics g)
        {
            Control.InitVars();
                Control.InitScrollbars();
                SetBrackets();
                SetSpanIndicators();
                int j = Control.View.FirstVisibleRow;

                int diff = j - this.LastRow;
                this.LastRow = j;
                if (this.Control.SmoothScroll)
                {
                    if (diff == 1)
                    {
                        for (int i = this.Control.View.RowHeight; i > 0; i -=
                            this.Control.SmoothScrollSpeed)
                        {
                            this.yOffset = i + this.Control.View.YOffset;
                            RenderAll2(g);
                            g.Flush();
                            //BOO Thread.Sleep(0);
                        }
                    }
                    else if (diff == -1)
                    {
                        for (int i = -this.Control.View.RowHeight; i < 0; i +=
                            this.Control.SmoothScrollSpeed)
                        {
                            this.yOffset = i + this.Control.View.YOffset;
                            RenderAll2(g);
                            g.Flush();
                            //BOO Thread.Sleep(0);
                        }
                    }
                }

                this.yOffset = this.Control.View.YOffset;
                RenderAll2(g);
                //g.Flush ();
                //System.Threading.Thread.Sleep (0);
        }
Esempio n. 57
0
 private void PreprocessFrame( Graphics gr, RecordSettings settings ) {
     if ( !settings.Private ) return;
     gr.Clear( Color.Black );
     gr.Flush();
 }
Esempio n. 58
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            g = Graphics.FromImage(bmp); g.FillRectangle(Brushes.Black, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
            
            
            
            Timer tc = new Timer();
            tc.Interval = 500;
            bool darkstyle=false;
            int w, h = 0;
            tc.Tick += (a, b) =>
            {
                w = pictureBox1.Width;
                h = pictureBox1.Height;
                int hf = int.Parse(Math.Floor(h / 2d).ToString());
                int wf = int.Parse(Math.Floor(w / 2d).ToString());
                int s = int.Parse(Math.Floor(Math.Min(wf, hf) / 2d).ToString());

                DateTime dt = DateTime.Now;
                darkstyle = dt.Hour > 18 || dt.Hour < 5;

                g.FillRectangle(darkstyle ? Brushes.Black : Brushes.Silver, new Rectangle(0, 0, w, h));
                Pen pen = new Pen(darkstyle ? Brushes.Gray : Brushes.Gray) { Width = s / 60 };

                g.DrawEllipse(pen, new Rectangle(wf-s, hf-s, s*2, s*2));

                pen = new Pen(darkstyle ? Brushes.Silver : Brushes.Black) { Width = s / 60 };
                for (double r = 0; r < (2 * Math.PI); r = r + (Math.PI / 30))
                {

                    var mx = cosx(r, .99,s,wf);
                    var my = sinx(r, .99,s,hf);                    

                    var x = cosx(r, 1.01,s,wf);
                    var y = sinx(r, 1.01,s,hf);
                    g.DrawLine(pen, new Point(mx, my), new Point(x, y));
                    
                }
                pen = new Pen(darkstyle ? Brushes.Silver : Brushes.Black) { Width = s / 20 };
                for (double r = 0; r < (2 * Math.PI); r = r + (Math.PI / 6))
                {
                    var mx = cosx(r, .9, s, wf);
                    var my = sinx(r, .9, s, hf);

                    var x = cosx(r, 1.1, s, wf);
                    var y = sinx(r, 1.1, s, hf);
                    g.DrawLine(pen, new Point(mx, my), new Point(x, y));

                }

                var ho = dt.Hour;
                if (ho > 12)
                    ho = ho - 12;
                var mi = dt.Minute;
                var se = dt.Second;
                var mse = dt.Millisecond;

                //Draw hours arm
		        var rho = (((Math.PI / 6) * ho) - ((Math.PI / 6) * 15)) + (mi/120);		    
                var hx = cosx(rho,.7,s,wf);
		        var hy = sinx(rho,.7,s,hf);
		        pen = new Pen(darkstyle ? Brushes.DarkGreen : Brushes.Green) { Width = s / 20 };
                g.DrawLine(pen, new Point(wf, hf), new Point(hx, hy));


                //Draw minutes arm
                var rmi = (((Math.PI / 30) * mi) - ((Math.PI / 30) * 15)) + (se / 720);
                var mix = cosx(rmi, .9, s, wf);
                var miy = sinx(rmi, .9, s, hf);
                pen = new Pen(darkstyle ? Brushes.DarkBlue : Brushes.Blue) { Width = s / 40 };
                g.DrawLine(pen, new Point(wf, hf), new Point(mix, miy));


                //Draw seconds arm
                var rse = ((Math.PI / 30) * se) - ((Math.PI / 30) * 15);//+ (mse/10000);
                var sx = cosx(rse, .95, s, wf);
                var sy = sinx(rse, .95, s, hf);
                var ssx = cosx(rse, -.25,s,wf);
                var ssy = sinx(rse, -.25,s,hf);
                pen = new Pen(darkstyle ? Brushes.Gray : Brushes.Black) { Width = s / 80 };
                g.DrawLine(pen, new Point(ssx, ssy), new Point(sx, sy));


                //Draw larger gray ring
                pen = new Pen(darkstyle ? Brushes.Gray : Brushes.Black) { Width = s / 80 };
                Rectangle rect = new Rectangle(wf - (s / 15), hf - (s / 15), (s / 15) * 2, (s / 15) * 2);
                g.DrawEllipse(pen, rect);
                g.FillEllipse(darkstyle ? Brushes.Silver : Brushes.Gray, rect);

                //Draw smaller gray ring
                pen = new Pen(darkstyle ? Brushes.Gray : Brushes.Black) { Width = s / 80 };
                Rectangle rect2 = new Rectangle(wf - (s / 55), hf - (s / 55), (s / 55) * 2, (s / 55) * 2);
                g.DrawEllipse(pen, rect2);
                g.FillEllipse(Brushes.Black, rect2);
                
                pictureBox1.Image = bmp;
            };
            tc.Start();
            return;
            
            Random rnd = new Random((new Random()).Next(65000));
            for (int i = 0; i < 50; i++)
            {
                int rx = (rnd.Next(speed * -1, speed));
                int ry = (rnd.Next(speed * -1, speed));
                Color color = Color.FromArgb(rnd.Next(50, 255), rnd.Next(50, 255), rnd.Next(50, 255));
                Ball ball = new Ball()
                    {
                        x=rnd.Next(0,pictureBox1.Width),
                        y=rnd.Next(0,pictureBox1.Height),
                        brush = new SolidBrush(color),
                        mx = rx != 0 ? rx : speed,
                        my = ry != 0 ? ry : speed*-1,
                        size=rnd.Next(2,20)
                    };
                balls.Add(ball);
                ball.isx = ball.x;
                ball.isy = ball.y;
                ball.polygon = getPolyGon(ball);
                //g.FillPie(ball.brush, new Rectangle(ball.x, ball.y, ball.size, ball.size), 0, 360);
                //g.FillPolygon(ball.brush, getPolyGon(ball));
            }
            Ball ball1 = new Ball() {
                x = rnd.Next(0, pictureBox1.Width),
                y = rnd.Next(0, pictureBox1.Height),
                brush = new SolidBrush(Color.White),
                size=100
            };
            g.DrawPolygon(Pens.White, getPolyGon(ball1));
            //
            //g.DrawString(lista.Count.ToString(), DefaultFont, Brushes.Blue, new Point(m - int.Parse(Math.Floor(DefaultFont.GetHeight()).ToString()), m - int.Parse(Math.Floor(DefaultFont.GetHeight()).ToString())));

            pictureBox1.Image = bmp;
            return;

            Timer t = new Timer();
            t.Interval = 5;
            t.Tick += (a, b) => {
                g.FillRectangle(Brushes.Black, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));

                if (line.Count > 0)
                {
                    foreach(List<Point> points in line)
                        g.FillPolygon(Brushes.White, points.ToArray());
                }
                if (tmpline.Count > 0)
                    g.DrawPolygon(Pens.Blue, tmpline.ToArray());

                g.Flush();
                List<Ball> remove = new List<Ball>();
                foreach (Ball ball in balls)
                {
                    
                    Point[] ps = ball.polygon;
                    if (ps.Where(p => p.Y < bmp.Height && p.X < bmp.Width && p.X > 0 && p.Y > 0 && (p.X + (ball.isx - ball.x)) > 0 && (p.Y + (ball.isy - ball.y)) > 0 && (p.X + (ball.isx - ball.x)) < bmp.Width && (p.Y + (ball.isy - ball.y)) < bmp.Height)
                        .Any(p => !bmp.GetPixel(p.X + (ball.isx - ball.x), p.Y + (ball.isy - ball.y)).Equals(ball.color))
                        )
                    {
                        g.DrawString("Jupp", DefaultFont, Brushes.YellowGreen, ball.x - 20, ball.y - 20);
                        ball.mx *= -1;
                        //ball.my *= -1;
                    }
                    else
                    {
                        if (ball.x <= 0 || ball.x + (ball.size / 2) >= pictureBox1.Width)
                        {
                            Color c = ball.color;
                            ball.color = Color.FromArgb(Math.Max(c.R - 1, 0), Math.Max(c.G - 1, 0), Math.Max(c.B - 1, 0));
                            ball.mx *= -1;
                        }

                        if (ball.y <= 0 || ball.y + (ball.size / 2) >= pictureBox1.Height)
                        {
                            Color c = ball.color;
                            ball.color = Color.FromArgb(Math.Max(c.R - 1, 0), Math.Max(c.G - 1, 0), Math.Max(c.B - 1, 0));
                            ball.my *= -1;
                        }
                    }
                    ball.x += ball.mx;
                    ball.y += ball.my;

                    g.FillPie(ball.brush, new Rectangle(ball.x, ball.y, ball.size, ball.size), 0, 360);
                    //g.FillPolygon(ball.brush, getPolyGon(ball));

                    Color c2 = (ball.brush as SolidBrush).Color;
                    if (c2.B < 10 || c2.R < 10 || c2.G < 10)
                        remove.Add(ball);

                }
                foreach (Ball ball in remove)
                    balls.Remove(ball);
                remove.Clear();


                this.Text = balls.Count.ToString();
                if (balls.Count == 0)
                    t.Stop();

                pictureBox1.Image = bmp;
            };
            t.Start();
        }