Esempio n. 1
0
        private void _update()
        {
            isUpdating = true;
            lock (buf1)
            {
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(buf1);
                g.Clear(System.Drawing.Color.Transparent);
                try
                {
                    c.ScrollOffset = new System.Drawing.PointF(offset.X, offset.Y);
                    c.PerformLayout(g);
                    c.PerformPaint(g);
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot display HTML page. Aborting...");

                    g.Clear(System.Drawing.Color.Transparent);
                    CopyBitmapToTexture();

                    loaded = true;
                    return;
                }
                lock (buf2)
                {
                    CopyBitmapToTexture();
                }
            }
            loaded     = true;
            isUpdating = false;
        }
Esempio n. 2
0
 public override void ClearScreen()
 {
     if (CheckInFrame())
     {
         gfx.Clear(System.Drawing.Color.Black);
     }
 }
Esempio n. 3
0
 public void WipeScreen(System.Drawing.Graphics CurGraphics)
 {
     //prntSome.printSome("WipeScreen");
     // clear the screen buffer area
     if ((this.Modes.Flags & uc_Mode.LightBackground) > 0)
     {
         CurGraphics.Clear(this.FGColor);
     }
     else
     {
         CurGraphics.Clear(this.BackColor);
     }
 }
Esempio n. 4
0
        public void ListeAusgeben(System.Drawing.Graphics zeichenflaeche, System.Drawing.RectangleF flaeche)
        {
            System.Drawing.SolidBrush tempPinsel = new System.Drawing.SolidBrush(System.Drawing.Color.White);

            System.Drawing.Font tempSchrift = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);

            System.Drawing.StringFormat ausrichtung = new System.Drawing.StringFormat();

            float punktX, nameX, Y;

            punktX = (flaeche.Right / 2) + 150;
            nameX  = (flaeche.Right / 2) - 150;
            Y      = flaeche.Top + 50;
            ausrichtung.Alignment = System.Drawing.StringAlignment.Center;

            zeichenflaeche.Clear(System.Drawing.Color.Black);

            for (int i = 0; i < 10; i++)
            {
                SoundPlayer simpleSound = new SoundPlayer("C:\\Shared\\ILS_Hefte\\Pong\\Sound\\piano2.wav");
                if ((i % 2) != 0)
                {
                    tempPinsel.Color = System.Drawing.Color.Pink;
                }
                else
                {
                    tempPinsel.Color = System.Drawing.Color.White;
                }

                zeichenflaeche.DrawString("/************************************Bestenliste************************************\\", tempSchrift, tempPinsel, flaeche.Width / 2, Y, ausrichtung);
                simpleSound.Play();
                System.Threading.Thread.Sleep(250);
                zeichenflaeche.Clear(System.Drawing.Color.Black);
            }
            zeichenflaeche.Clear(System.Drawing.Color.Black);
            zeichenflaeche.DrawString("/************************************Bestenliste************************************\\", tempSchrift, tempPinsel, flaeche.Width / 2, Y, ausrichtung);
            Y = Y + 30;
            for (int i = 0; i < anzahl; i++)
            {
                Y = Y + 20;

                zeichenflaeche.DrawString(Convert.ToString(bestenliste[i].GetPunkte()), tempSchrift, tempPinsel, punktX, Y);

                zeichenflaeche.DrawString(Convert.ToString(bestenliste[i].GetName()), tempSchrift, tempPinsel, nameX, Y);
                System.Threading.Thread.Sleep(100);
            }
            zeichenflaeche.DrawString("\\************************************************************************************/", tempSchrift, tempPinsel, flaeche.Width / 2, (Y + 50), ausrichtung);
        }
Esempio n. 5
0
        private void _load()
        {
            if (raw == "")
            {
                loaded = true;
                return;
            }
            offset = new Vector2();
            lock (buf1)
            {
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(buf1);
                g.Clear(System.Drawing.Color.Transparent);
                //CopyBitmapToTexture();
                try
                {
                    //HtmlRenderer.HtmlRender.Render(g, raw, new System.Drawing.PointF(), new System.Drawing.SizeF(size.X, size.Y));
                    c = new HtmlRenderer.HtmlContainer();
                    c.AvoidImagesLateLoading = false;
                    c.Location   = new System.Drawing.PointF();
                    c.MaxSize    = new System.Drawing.SizeF(size.X, size.Y);
                    c.ImageLoad += new EventHandler <HtmlRenderer.Entities.HtmlImageLoadEventArgs>(c_ImageLoad);
                    c.SetHtml(raw);
                    c.PerformLayout(g);
                    c.PerformPaint(g);
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot display HTML page. Aborting...");

                    g.Clear(System.Drawing.Color.Transparent);
                    CopyBitmapToTexture();

                    loaded = true;
                    return;
                }
                //System.Threading.Thread.Sleep(100);
                lock (buf2)
                {
                    CopyBitmapToTexture();
                    //SetBackground();
                }
            }
            if (OnPageLoaded != null)
            {
                OnPageLoaded.Invoke();
            }
            loaded = true;
        }
Esempio n. 6
0
        public void CreateImage(string str_ValidateCode)
        {
            int    int_ImageWidth = str_ValidateCode.Length * 14;
            Random newRandom      = new Random();

            System.Drawing.Bitmap   theBitmap   = new System.Drawing.Bitmap(int_ImageWidth, 20);
            System.Drawing.Graphics theGraphics = System.Drawing.Graphics.FromImage(theBitmap);
            theGraphics.Clear(System.Drawing.Color.White);
            theGraphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.LightGray, 1), 0, 0, int_ImageWidth - 1, 19);
            System.Drawing.Font theFont = new System.Drawing.Font("Arial", 10);
            for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
            {
                string str_char = str_ValidateCode.Substring(int_index, 1);
                System.Drawing.Brush newBrush = new System.Drawing.SolidBrush(GetRandomColor());
                System.Drawing.Point thePos   = new System.Drawing.Point(int_index * 13 + 1 + newRandom.Next(3), 1 + newRandom.Next(3));
                theGraphics.DrawString(str_char, theFont, newBrush, thePos);
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            theBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            Response.ClearContent();
            Response.ContentType = "image/Png";
            Response.BinaryWrite(ms.ToArray());
            theGraphics.Dispose();
            theBitmap.Dispose();
            Response.End();
        }
Esempio n. 7
0
 /// <summary>
 /// 产生验证码图片二进制流
 /// </summary>
 /// <param name="CodeLength">验证码长度</param>
 /// <param name="InputImageWidth">图片宽度</param>
 /// <param name="InputImageHeight">图片高度</param>
 /// <param name="VelidateCode">验证码的真实值</param>
 public static byte[] CreateValidateCode(int CodeLength, int InputImageWidth, int InputImageHeight, out string VelidateCode)
 {
     VelidateCode = GenerateRandomChareNumString(CodeLength);
     byte[] reVal = null;
     #region 画出验证码
     System.Drawing.Bitmap   image = new System.Drawing.Bitmap(InputImageWidth, InputImageHeight);
     System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
     try
     {
         System.Random random = new Random();
         g.Clear(System.Drawing.Color.White);
         System.Drawing.Font font = new System.Drawing.Font("Microsoft Yahei", 16, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
         System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 1.2f, true);
         g.DrawString(VelidateCode, font, brush, 2, 2);
         for (int i = 0; i < InputImageWidth * InputImageHeight / 5; i++)
         {
             int x = random.Next(image.Width);
             int y = random.Next(image.Height);
             image.SetPixel(x, y, System.Drawing.Color.FromArgb(random.Next()));
         }
         g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Black), 0, 0, image.Width - 1, image.Height - 1);
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
         reVal = ms.ToArray();
         return(reVal);
     }
     finally
     {
         g.Dispose();
         image.Dispose();
     }
     #endregion 画出验证码
 }
Esempio n. 8
0
        internal static Image RGBToBGR(this Image bmp)
        {
            Image newBmp;

            if ((bmp.PixelFormat & Imaging.PixelFormat.Indexed) != 0)
            {
                newBmp = new Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb);
            }
            else
            {
                newBmp = bmp;
            }

            try
            {
                System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
                System.Drawing.Imaging.ColorMatrix     cm = new System.Drawing.Imaging.ColorMatrix(rgbtobgr);

                ia.SetColorMatrix(cm);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBmp))
                {
                    g.Clear(Color.Transparent);
                    g.DrawImage(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel, ia);
                }
            }
            finally
            {
                if (newBmp != bmp)
                {
                    bmp.Dispose();
                }
            }

            return(newBmp);
        }
Esempio n. 9
0
        }     // End Sub CosineTest

        public static void Test()
        {
            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1000, 1000))
            {
                using (System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(bmp))
                {
                    gfx.Clear(System.Drawing.Color.White);
                    PaintComponent(gfx);
                }

                bmp.Save(@"D:\Perspective.png", System.Drawing.Imaging.ImageFormat.Png);
            }

            System.Console.WriteLine("Drawn !");

            // https://math.stackexchange.com/questions/2305792/3d-projection-on-a-2d-plane-weak-maths-ressources
            // https://en.wikipedia.org/wiki/Axonometric_projection
            // https://en.wikipedia.org/wiki/3D_projection
            // https://en.wikipedia.org/wiki/Perspective_(graphical)
            // https://en.wikipedia.org/wiki/Oblique_projection
            // https://en.wikipedia.org/wiki/Isometric_video_game_graphics

            // https://en.wikipedia.org/wiki/Orthographic_projection
            // https://en.wikipedia.org/wiki/Parallel_projection
            // https://en.wikipedia.org/wiki/Plan_(drawing)
            // https://en.wikipedia.org/wiki/Multiview_projection


            // https://stackoverflow.com/questions/724219/how-to-convert-a-3d-point-into-2d-perspective-projection
            // https://stackoverflow.com/questions/15079764/3d-to-2d-point-conversion
            // https://github.com/Fylax/Apache-Commons-Math3-C-
            // https://github.com/mrdefnerd/Arrav-Server-Provider/blob/dce7fae5f9f8ccec0f795c1cbe486ef570c41273/org/rev317/api/methods/Calculations.java
        } // End Sub Test
Esempio n. 10
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            // Create workbook object from source file
            Workbook workbook = new Workbook(sourceDir + "sampleRenderWorksheetToGraphicContext.xlsx");

            // Access first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Create empty Bitmap
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1100, 600);

            // Create Graphics Context
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Blue);

            // Set one page per sheet to true in image or print options
            Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            opts.OnePagePerSheet = true;

            // Render worksheet to graphics context
            Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts);
            sr.ToImage(0, g, 0, 0);

            // Save the graphics context image in Png format
            bmp.Save(outputDir + "outputRenderWorksheetToGraphicContext.png", System.Drawing.Imaging.ImageFormat.Png);

            Console.WriteLine("RenderWorksheetToGraphicContext executed successfully.");
        }
Esempio n. 11
0
        //Draw text on the map
        private System.Drawing.Bitmap DrawText(String text, System.Drawing.Font font, System.Drawing.Color textColor, System.Drawing.Color backColor)
        {
            //Create a dummy bitmap to get a graphics object
            System.Drawing.Bitmap   img     = new System.Drawing.Bitmap(1, 1);
            System.Drawing.Graphics drawing = System.Drawing.Graphics.FromImage(img);

            //Measure the string to see how big the image needs to be
            textSize = drawing.MeasureString(text, font);

            //free up the dummy image and old graphics object
            img.Dispose();
            drawing.Dispose();

            //create a new image of the right size
            img     = new System.Drawing.Bitmap((int)textSize.Width, (int)textSize.Height);
            drawing = System.Drawing.Graphics.FromImage(img);

            //paint the background
            drawing.Clear(backColor);

            System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(textColor);
            drawing.DrawString(text, font, textBrush, 0, 0);
            drawing.Save();
            textBrush.Dispose();
            drawing.Dispose();

            return(img);
        }
        public void DrawTileMap(DevicePanel d, int x, int y, int platform_x, int platform_y, int platform_width, int platform_height, System.Drawing.Color colors, int transparency, bool TilesNeedUpdate = false)
        {
            if (ScatchLayer != null)
            {
                if (ScatchLayer.Visible)
                {
                    if (TileMap == null || TileMap != ScatchLayer.Layer.Tiles || TilesNeedUpdate || PlatformImage == null)
                    {
                        if (PlatformImage != null)
                        {
                            PlatformImage.Dispose();
                            PlatformImage = null;
                        }

                        TileMap = ScatchLayer.Tiles;

                        var bitmap = new System.Drawing.Bitmap(ScatchLayer.Width * Methods.Solution.SolutionConstants.TILE_SIZE, ScatchLayer.Height * Methods.Solution.SolutionConstants.TILE_SIZE);
                        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
                        ScatchLayer.Draw(g);
                        PlatformImage = Methods.Drawing.TextureCreator.FromBitmap(d._device, bitmap);
                        g.Clear(System.Drawing.Color.Transparent);
                        bitmap.Dispose();
                        g.Dispose();
                    }

                    d.DrawBitmap(PlatformImage, x, y, platform_x, platform_y, platform_width, platform_height, false, transparency, false, false, 0, colors);
                }
            }
        }
Esempio n. 13
0
 public static void Reset()
 {
     if (!Logic.fast_forward)
     {
         canvas.Clear(System.Drawing.Color.Black);
     }
 }
Esempio n. 14
0
 public static System.Drawing.Image RezizeImage(System.Drawing.Image img, int maxWidth, int maxHeight)
 {
     if (img.Height < maxHeight && img.Width < maxWidth)
     {
         return(img);
     }
     using (img)
     {
         Double xRatio             = (double)img.Width / maxWidth;
         Double yRatio             = (double)img.Height / maxHeight;
         Double ratio              = Math.Max(xRatio, yRatio);
         int    nnx                = (int)Math.Floor(img.Width / ratio);
         int    nny                = (int)Math.Floor(img.Height / ratio);
         System.Drawing.Bitmap cpy = new System.Drawing.Bitmap(nnx, nny, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(cpy))
         {
             gr.Clear(System.Drawing.Color.Transparent);
             // This is said to give best quality when resizing images
             gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
             gr.DrawImage(img,
                          new System.Drawing.Rectangle(0, 0, nnx, nny),
                          new System.Drawing.Rectangle(0, 0, img.Width, img.Height),
                          System.Drawing.GraphicsUnit.Pixel);
         }
         return(cpy);
     }
 }
        public void Reset(int hPageNum, int vPageNum, int newWidth, int newHeight)
        {
            this.pageNumFlags = (hPageNum << 8) | vPageNum;
            this.ReleaseUnManagedResource();
            this.ClearPreviousStoredValues();

            var orgHdc = MyWin32.CreateCompatibleDC(IntPtr.Zero);

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            hbmp = bmp.GetHbitmap();
            MyWin32.SelectObject(orgHdc, hbmp);
            MyWin32.PatBlt(orgHdc, 0, 0, newWidth, newHeight, MyWin32.WHITENESS);
            MyWin32.SetBkMode(orgHdc, MyWin32._SetBkMode_TRANSPARENT);


            hFont = defaultHFont;

            MyWin32.SelectObject(orgHdc, hFont);
            currentClipRect = new System.Drawing.Rectangle(0, 0, newWidth, newHeight);
            MyWin32.SelectObject(orgHdc, hRgn);
            gx = System.Drawing.Graphics.FromHdc(orgHdc);
            this.originalHdc = orgHdc;

            gx.Clear(System.Drawing.Color.White);
            MyWin32.SetRectRgn(hRgn, 0, 0, newWidth, newHeight);


            left   = hPageNum * newWidth;
            top    = vPageNum * newHeight;
            right  = left + newWidth;
            bottom = top + newHeight;
#if DEBUG
            debug_resetCount++;
#endif
        }
Esempio n. 16
0
        private void BuildFontSheetBitmap(System.Drawing.Font font, System.Drawing.Graphics charGraphics, System.Drawing.Bitmap charBitmap, System.Drawing.Graphics fontSheetGraphics)
        {
            Int32 fontSheetX = 0;
            Int32 fontSheetY = 0;

            for (Int32 index = 0; index < DXFont.NumChars; ++index)
            {
                charGraphics.Clear(System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black));
                charGraphics.DrawString(((Char)(StartChar + index)).ToString(), font, System.Drawing.Brushes.White, new System.Drawing.PointF(0.0f, 0.0f));

                Int32 minX      = this.GetCharMinX(charBitmap);
                Int32 maxX      = this.GetCharMaxX(charBitmap);
                Int32 charWidth = maxX - minX + 1;

                if (fontSheetX + charWidth >= this.TexWidth)
                {
                    fontSheetX  = 0;
                    fontSheetY += this.CharHeight + 1;
                }

                this.CharRects[index] = new RawRectangle(fontSheetX, fontSheetY, charWidth, this.CharHeight);
                fontSheetGraphics.DrawImage(charBitmap, fontSheetX, fontSheetY, new System.Drawing.Rectangle(minX, 0, charWidth, this.CharHeight), System.Drawing.GraphicsUnit.Pixel);
                fontSheetX += charWidth + 1;
            }
        }
Esempio n. 17
0
        protected static void drawBuffer(System.Drawing.Graphics g)
        {
            //base.OnPaint(e);


            g.Clear(System.Drawing.Color.Black);
            //System.Console.WriteLine(i+ " " + x);
            g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White), 50, 0, i + 50, 100);


            wuerfel.punkte = Matrix.multiplizieren(wuerfel.punkte, drehmatrix1grad);

            //System.Console.WriteLine(i+ " " + y);
            g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White), 150, 0, j + 150, 150);
            for (int k = 0; k < 8; k++)
            {
                g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Color.Blue), center[0] - 2 + (int)wuerfel.punkte[k][0] + (int)(wuerfel.punkte[k][2] * 0.1), (int)center[1] - 2 + (int)(wuerfel.punkte[k][1] + wuerfel.punkte[k][2] * 0.1), 5, 5);
            }

            for (int l = 0; l < wuerfel.W.Length; l++)
            {
                wuerfel.W[l] = Matrix.multiplizieren(wuerfel.W[l], drehmatrix1grad);
                g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue), (float)(center[0] + wuerfel.W[l][0][0] + wuerfel.W[l][0][2] * 0.1), (float)(center[1] + wuerfel.W[l][0][1] + wuerfel.W[l][0][2] * 0.1), (float)(center[0] + wuerfel.W[l][1][0] + wuerfel.W[l][1][2] * 0.1), (float)(center[1] + wuerfel.W[l][1][1] + wuerfel.W[l][1][2] * 0.1));
            }

            g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.White), i + 50, 100, j + 150, 150);
        }
Esempio n. 18
0
 /// <summary>
 /// 冻结用户界面
 /// </summary>
 public void FreezeUI()
 {
     if (_FreezeUIBmp == null)
     {
         System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
             this.ClientSize.Width,
             this.ClientSize.Height);
         using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
         {
             g.Clear(this.BackColor);
             System.Windows.Forms.PaintEventArgs args = new PaintEventArgs(
                 g,
                 new System.Drawing.Rectangle(
                     0,
                     0,
                     this.ClientSize.Width,
                     this.ClientSize.Height));
             this.OnPaint(args);
         }
         _FreezeUIBmp = bmp;
         //this.DrawToBitmap(
         //    _FreezeUIBmp,
         //    new System.Drawing.Rectangle(
         //        0,
         //        0,
         //        this.ClientSize.Width,
         //        this.ClientSize.Height));
     }
 }
Esempio n. 19
0
        public void ListeAusgabe(System.Drawing.Graphics zeichenflaeche, System.Drawing.RectangleF flaesche)
        {
            //ein Temporär Pinsel erzeugen
            System.Drawing.SolidBrush tempPinsle = new System.Drawing.SolidBrush(System.Drawing.Color.White);
            //die schriftart setzen
            System.Drawing.Font tempSchrift = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);

            //für die zentrierte ausgabe
            System.Drawing.StringFormat ausrichtung = new System.Drawing.StringFormat();
            //Koordinaten für die ausgabe
            float punkteX, nameX, y;

            punkteX = flaesche.Left + 50;
            nameX   = flaesche.Left + 250;
            y       = flaesche.Top + 50;
            //die ausrichtung ist zentriert
            ausrichtung.Alignment = System.Drawing.StringAlignment.Center;
            //die zeichenflaeche löschen
            zeichenflaeche.Clear(System.Drawing.Color.Black);
            //den Titel ausgeben
            zeichenflaeche.DrawString("Bestenliste", tempSchrift, tempPinsle, flaesche.Width / 2, y, ausrichtung);
            //und nun die liste selbst
            for (int i = 0; i < anzahl; i++)
            {
                y += 20;
                zeichenflaeche.DrawString(Convert.ToString(bestenListe[i].GetPunkte()), tempSchrift, tempPinsle, punkteX, y);
                zeichenflaeche.DrawString(Convert.ToString(bestenListe[i].GetName()), tempSchrift, tempPinsle, nameX, y);
            }
        }
        /// <summary>
        /// Updates the background image, adds a border in order to enable
        /// pixel selection around the edges, and modifies the size of this window
        /// </summary>
        /// <param name="context">ElementContext containing screenshot</param>
        public void UpdateBackground(ElementContext context)
        {
            var screenshot = context?.DataContext?.Screenshot;

            this.EC = context;
            if (screenshot != null)
            {
                this.backgroundImageScale = Axe.Windows.Desktop.Utility.ExtensionMethods.GetDPI(
                    (int)System.Windows.Application.Current.MainWindow.Top,
                    (int)System.Windows.Application.Current.MainWindow.Left);

                // Increase size and add white border (this is so we can magnify the corners without having to worry about resizing the magnifier preview
                System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap((int)(screenshot.Width + MagnifyRadius * 2), (int)(screenshot.Height + MagnifyRadius * 2));
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newBitmap))
                {
                    g.Clear(System.Drawing.Color.White);
                    g.DrawImageUnscaled(screenshot, MagnifyRadius, MagnifyRadius);
                }

                // Size to scale to
                var ourImageWidth  = (screenshot.Width + MagnifyRadius * 2) / this.backgroundImageScale;
                var ourImageHeight = (screenshot.Height + MagnifyRadius * 2) / this.backgroundImageScale;
                this.background     = newBitmap;
                this.image.Source   = background.ConvertToSource();
                this.image.Width    = ourImageWidth;
                this.image.Height   = ourImageHeight;
                this.grid.MaxWidth  = ourImageWidth;
                this.grid.MaxHeight = ourImageHeight;
                this.Width          = Math.Min(Math.Max(ourImageWidth, MIN_INITIAL_WINDOW_WIDTH), INITIAL_WINDOW_WIDTH);
                this.Height         = Math.Min(Math.Max(ourImageHeight, MIN_INITIAL_WINDOW_HEIGHT), INITIAL_WINDOW_HEIGHT);

                ChangeMagnifierPositionBy(0, 0); // shows initial magnified state
            }
        }
Esempio n. 21
0
        public System.Drawing.Bitmap DrawPie()
        {
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image)) {
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                g.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.Clear(System.Drawing.Color.Transparent);


                float centerLabelMaxWidth   = GetLabelMaxWidth(g) + 10F;
                float centerPercentMaxWidth = g.MeasureString("999.999 " + "99.9%", _font).Width + 3F;

                float widthSplitOffset   = 20F;
                float heightSplitOffset  = 10F;
                float bottomHeightOffset = 20F;
                float pieWidth           = (Width - (widthSplitOffset * 4F) - centerLabelMaxWidth - centerPercentMaxWidth * 2) / 2F - 20F - _font.Height;
                float pieHeight          = (Height - (heightSplitOffset * 2F) - bottomHeightOffset);
                pieHeight = pieWidth = System.Math.Min(pieWidth, pieHeight);

                _leftPie.Width  = pieWidth; _leftPie.Height = pieHeight;
                _leftPie.X      = widthSplitOffset; _leftPie.Y = heightSplitOffset;
                _rightPie.Width = pieWidth; _rightPie.Height = pieHeight;
                _rightPie.X     = Width - widthSplitOffset - pieWidth; _rightPie.Y = heightSplitOffset;


                RenderPie(true, g);
                RenderPie(false, g);
                RenderCenterLabels(g, pieWidth + widthSplitOffset * 2F + centerPercentMaxWidth, centerLabelMaxWidth, centerPercentMaxWidth);
            }

            return(image);
        }
Esempio n. 22
0
 ///<summary>
 /// 对给定的一个图片(Image对象)生成一个指定大小的缩略图。
 ///</summary>
 ///<param name="originalImage">原始图片</param>
 ///<param name="thumMaxWidth">缩略图的宽度</param>
 ///<param name="thumMaxHeight">缩略图的高度</param>
 ///<returns>返回缩略图的Image对象</returns>
 public static System.Drawing.Image GetThumbNailImage(System.Drawing.Image originalImage, int thumMaxWidth, int thumMaxHeight)
 {
     System.Drawing.Size     thumRealSize = System.Drawing.Size.Empty;
     System.Drawing.Image    newImage     = originalImage;
     System.Drawing.Graphics graphics     = null;
     try
     {
         thumRealSize = GetNewSize(thumMaxWidth, thumMaxHeight, originalImage.Width, originalImage.Height);
         newImage     = new System.Drawing.Bitmap(thumRealSize.Width, thumRealSize.Height);
         graphics     = System.Drawing.Graphics.FromImage(newImage);
         graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
         graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
         graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         graphics.Clear(System.Drawing.Color.Transparent);
         graphics.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, thumRealSize.Width, thumRealSize.Height), new System.Drawing.Rectangle(0, 0, originalImage.Width, originalImage.Height), System.Drawing.GraphicsUnit.Pixel);
     }
     catch { }
     finally
     {
         if (graphics != null)
         {
             graphics.Dispose();
             graphics = null;
         }
     }
     return(newImage);
 }
Esempio n. 23
0
        /// <summary>
        /// Renders the map to an image
        /// </summary>
        /// <returns></returns>
        public System.Drawing.Image GetMap()
        {
            if (Layers == null || Layers.Count == 0)
            {
                throw new InvalidOperationException("No layers to render");
            }

            System.Drawing.Image    img = new System.Drawing.Bitmap(this.Size.Width, this.Size.Height);
            System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(img);
            g.Transform = this.MapTransform;
            g.Clear(this.BackColor);
            g.PageUnit = System.Drawing.GraphicsUnit.Pixel;
            int SRID = (Layers.Count > 0 ? Layers[0].SRID : -1);             //Get the SRID of the first layer

            for (int i = 0; i < _Layers.Count; i++)
            {
                if (_Layers[i].Enabled && _Layers[i].MaxVisible >= this.Zoom && _Layers[i].MinVisible < this.Zoom)
                {
                    _Layers[i].Render(g, this);
                }
            }
            if (MapRendered != null)
            {
                MapRendered(g);                                  //Fire render event
            }
            g.Dispose();
            return(img);
        }
Esempio n. 24
0
        public static System.Drawing.Image DrawHatchRectangleToImg(int iLegendPattern, System.Drawing.Color colFC, System.Drawing.Color colHB, System.Drawing.Color colHL)
        {
            int iBulletSize = 20;

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(iBulletSize, iBulletSize);


            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                g.Clear(System.Drawing.Color.White);

                // Add legend rectangle with color
                using (System.Drawing.Brush CurrentBrush = GetBrush(iLegendPattern, colFC, colHB, colHL))
                {
                    System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(0, 0, iBulletSize, iBulletSize);

                    if (CurrentBrush != null)
                    {
                        //if (object.ReferenceEquals(CurrentBrush, typeof(TextureBrush)))
                        if (CurrentBrush is System.Drawing.TextureBrush)
                        {
                            ((System.Drawing.TextureBrush)CurrentBrush).TranslateTransform(rect2.X, rect2.Y);
                        }

                        // Punkt - Quadrat
                        g.FillRectangle(CurrentBrush, rect2);
                        // cDrawingTools.FillTriangle(g, CurrentBrush, iOriginX, iOriginY, i, iBulletSize);
                        // cDrawingTools.FillCircle(g, CurrentBrush, iOriginX + iBulletSize / 2.0f, iOriginY + i * (iBulletSize * 2) + iBulletSize / 2.0f, iBulletSize / 2.0f);
                    } // End if (CurrentBrush != null)
                }     // End Using System.Drawing.Brush CurrentBrush
            }

            return(bmp);
        } // End Sub
Esempio n. 25
0
        static public System.Drawing.SizeF MeasureDisplayString(System.Drawing.Graphics graphics, string text, System.Drawing.Font font)
        {
            const int width = 32;

            System.Drawing.Bitmap   bitmap = new System.Drawing.Bitmap(width, 1, graphics);
            System.Drawing.SizeF    size   = graphics.MeasureString(text, font);
            System.Drawing.Graphics anagra = System.Drawing.Graphics.FromImage(bitmap);

            int measured_width = (int)size.Width;

            if (anagra != null)
            {
                anagra.Clear(System.Drawing.Color.White);
                anagra.DrawString(text + "|", font, System.Drawing.Brushes.Black, width - measured_width, -font.Height / 2);

                for (int i = width - 1; i >= 0; i--)
                {
                    measured_width--;
                    if (bitmap.GetPixel(i, 0).R == 0)
                    {
                        break;
                    }
                }
            }

            return(new System.Drawing.SizeF(measured_width, size.Height));
        }
Esempio n. 26
0
        static System.Drawing.Bitmap CreateBackgroundBmp(int w, int h)
        {
            //----------------------------------------------------
            //1. create background bitmap
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h);
            //2. create graphics from bmp
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            // draw a background to show how the mask is working better
            g.Clear(System.Drawing.Color.White);
            int rect_w = 30;

            var v1 = new VertexStore();//todo; use pool

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        VxsHelper.FillVxsSnap(g, new VertexStoreSnap(rect.MakeVxs(v1)), Drawing.Color.Make(.9f, .9f, .9f));
                        v1.Clear();
                    }
                }
            }

            //----------------------------------------------------
            return(bmp);
        }
Esempio n. 27
0
        void BuildFontSheetBitmap(System.Drawing.Font font, System.Drawing.Graphics charGraphics, System.Drawing.Bitmap charBitmap, System.Drawing.Graphics fontSheetGraphics)
        {
            System.Drawing.Brush whiteBrush = System.Drawing.Brushes.White;
            int fontSheetX = 0;
            int fontSheetY = 0;


            for (int i = 0; i < NumChars; ++i)
            {
                charGraphics.Clear(System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black));
                charGraphics.DrawString(((char)(StartChar + i)).ToString(), font, whiteBrush, new System.Drawing.PointF(0.0f, 0.0f));

                int minX      = GetCharMinX(charBitmap);
                int maxX      = GetCharMaxX(charBitmap);
                int charWidth = maxX - minX + 1;

                if (fontSheetX + charWidth >= _texWidth)
                {
                    fontSheetX  = 0;
                    fontSheetY += (int)(_charHeight) + 1;
                }

                _charRects[i] = new Rectangle(fontSheetX, fontSheetY, charWidth, _charHeight);

                fontSheetGraphics.DrawImage(charBitmap, fontSheetX, fontSheetY, new System.Drawing.Rectangle(minX, 0, charWidth, _charHeight), System.Drawing.GraphicsUnit.Pixel);

                fontSheetX += charWidth + 1;
            }
        }
        public static void Run()
        {
            // ExStart:RenderWorksheetToGraphicContext
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object from source file
            Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx");

            // Access first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Create empty Bitmap
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1100, 600);

            // Create Graphics Context
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Blue);

            // Set one page per sheet to true in image or print options
            Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            opts.OnePagePerSheet = true;

            // Render worksheet to graphics context
            Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts);
            sr.ToImage(0, g, 0, 0);

            // Save the graphics context image in Png format
            bmp.Save(dataDir + "OutputImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
            //ExEnd:RenderWorksheetToGraphicContext
        }
        internal void PrepareTextureForDrawDevice(IDrawDevice device)
        {
            System.Drawing.PointF[] points = new System.Drawing.PointF[_verticesPositions.Count];

            /**
             * Drawing texture based on displacement for each camera
             **/
            Vector3 start = _absoluteStart * device.GetScaleAtZ(_absoluteStart.Z);
            Vector3 end   = _absoluteEnd * device.GetScaleAtZ(_absoluteEnd.Z);

            Vector2 tangent = (end - start).Xy;
            float   length  = tangent.Length;

            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new System.Drawing.PointF(_verticesPositions[i].X * length, _verticesPositions[i].Y);
            }

            System.Drawing.Bitmap pixelData = new System.Drawing.Bitmap((int)MathF.Ceiling(length), (int)MathF.Ceiling(_sway2));

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(pixelData))
            {
                g.Clear(System.Drawing.Color.Transparent);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                g.DrawLines(_pen, points);
            }

            if (!BatchInfos.ContainsKey(device))
            {
                BatchInfo bi = new BatchInfo(
                    DrawTechnique.Add,
                    Colors.White,
                    new ContentRef <Texture>(
                        new Texture(new ContentRef <Pixmap>(new Pixmap()))
                {
                    FilterMin   = TextureMinFilter.LinearMipmapLinear,
                    FilterMag   = TextureMagFilter.LinearSharpenSgis,
                    WrapX       = TextureWrapMode.ClampToEdge,
                    WrapY       = TextureWrapMode.ClampToEdge,
                    TexSizeMode = Texture.SizeMode.Stretch
                }));

                BatchInfos.Add(device, new BoltData()
                {
                    BatchInfo = bi
                });
            }

            BoltData bd = BatchInfos[device];

            Texture tx = bd.BatchInfo.MainTexture.Res;

            tx.BasePixmap.Res.MainLayer.FromBitmap(pixelData);
            tx.ReloadData();

            bd.Start   = start;
            bd.End     = end;
            bd.IsReady = true;
        }
Esempio n. 30
0
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="serverImagePath">图片地址</param>
        /// <param name="thumbnailImagePath">缩略图地址</param>
        /// <param name="width">图片宽度</param>
        /// <param name="height">图片高度</param>
        /// <param name="SaveFileName">保存到数据的名称</param>
        /// <param name="imei">设备的IMEI号</param>
        public String GetThumbnail(string serverImagePath, string thumbnailImagePath, int width, int height, String SaveFileName)
        {
            try
            {
                System.Drawing.Image serverImage = System.Drawing.Image.FromFile(serverImagePath);

                //画板大小
                int towidth  = width;
                int toheight = height;
                //缩略图矩形框的像素点
                //int x = 0;
                //int y = 0;
                int ow = serverImage.Width;
                int oh = serverImage.Height;

                //if (ow > oh)
                //{
                //    toheight = serverImage.Height * width / serverImage.Width;
                //}
                //else
                //{
                //    towidth = serverImage.Width * height / serverImage.Height;
                //}
                //新建一个bmp图片
                System.Drawing.Image bm = new System.Drawing.Bitmap(width, height);
                //新建一个画板
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm);
                //设置高质量插值法
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                //设置高质量,低速度呈现平滑程度
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //清空画布并以透明背景色填充
                g.Clear(System.Drawing.Color.White);
                //在指定位置并且按指定大小绘制原图片的指定部分
                g.DrawImage(serverImage, new System.Drawing.Rectangle((width - towidth) / 2, (height - toheight) / 2, towidth, toheight), 0, 0, ow, oh, System.Drawing.GraphicsUnit.Pixel);
                try
                {
                    //以jpg格式保存缩略图
                    bm.Save(thumbnailImagePath);
                    return("{\"success\":\"" + SaveFileName + "\"}");
                }
                catch (System.Exception e)
                {
                    return("{\"success\":\"false\"}");
                }
                finally
                {
                    serverImage.Dispose();
                    bm.Dispose();
                    g.Dispose();
                    File.Delete(serverImagePath);
                }
            }
            catch (Exception)
            {
                File.Delete(serverImagePath);
                return("{\"success\":\"false\"}");
            }
        }
Esempio n. 31
0
        public void ShowBorders(object sender,MouseEventArgs e)
        {
            Panel tPanel = (Panel)sender;

            if (objGraphics != null) return;
            else objGraphics = null;
            objGraphics = tPanel.CreateGraphics();
            objGraphics.Clear(System.Drawing.SystemColors.Control);

            foreach(Control pp in tPanel.Controls)
            {
                if (pp is PictureBox)
                {
                    //画边界
                    objGraphics.DrawRectangle(System.Drawing.Pens.BlueViolet, pp.Left - 1, pp.Top - 1, pp.Width + 1, pp.Height + 1);
                }
                else objGraphics = null;
            }
        }
Esempio n. 32
0
        public static void PaintUsingSystemDrawing(GdiGraphics graphics, string text, GdiRectangle clientRectangle)
        {
            graphics.Clear(GdiColor.CornflowerBlue);

            using (var brush = new GdiSolidBrush(GdiColor.Black))
            using (var format = new GdiStringFormat())
            {
                format.Alignment = GdiStringAlignment.Center;
                format.LineAlignment = GdiStringAlignment.Center;

                graphics.DrawString(text, GdiSystemFonts.MessageBoxFont, brush, clientRectangle, format);
            }
        }