Esempio n. 1
0
        public System.Drawing.Bitmap KiRotate(System.Drawing.Bitmap bmp, float angle)
        {
            int w = bmp.Width + 2;
            int h = bmp.Height + 2;

            System.Drawing.Imaging.PixelFormat pf;

            pf = bmp.PixelFormat;

            System.Drawing.Bitmap   tmp = new System.Drawing.Bitmap(w, h, pf);
            System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(tmp);
            //g.Clear(bkColor);
            g.DrawImageUnscaled(bmp, 1, 1);
            g.Dispose();

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddRectangle(new System.Drawing.RectangleF(0f, 0f, w, h));
            System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.Matrix();
            mtrx.Rotate(angle);
            System.Drawing.RectangleF rct = path.GetBounds(mtrx);

            System.Drawing.Bitmap dst = new System.Drawing.Bitmap((int)rct.Width, (int)rct.Height, pf);
            g = System.Drawing.Graphics.FromImage(dst);
            //g.Clear(bkColor);
            g.TranslateTransform(-rct.X, -rct.Y);
            g.RotateTransform(angle);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.DrawImageUnscaled(tmp, 0, 0);
            g.Dispose();

            tmp.Dispose();

            return(dst);
        }
Esempio n. 2
0
        /// <summary>
        /// Renders a point to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="point">Point to render</param>
        /// <param name="symbol">Symbol to place over point</param>
        /// <param name="symbolscale">The amount that the symbol should be scaled. A scale of '1' equals to no scaling</param>
        /// <param name="offset">Symbol offset af scale=1</param>
        /// <param name="rotation">Symbol rotation in degrees</param>
        /// <param name="map">Map reference</param>
        public static void DrawPoint(System.Drawing.Graphics g, IPoint point, System.Drawing.Bitmap symbol, float symbolscale, System.Drawing.PointF offset, float rotation, SharpMap.Map map)
        {
            if (point == null)
            {
                return;
            }
            if (symbol == null)             //We have no point style - Use a default symbol
            {
                symbol = defaultsymbol;
            }

            System.Drawing.PointF pp = SharpMap.Utilities.Transform.WorldtoMap(point.Coordinate, map);

            Matrix startingTransform = g.Transform;

            if (rotation != 0 && !Single.IsNaN(rotation))
            {
                System.Drawing.PointF rotationCenter = System.Drawing.PointF.Add(pp, new System.Drawing.SizeF(symbol.Width / 2, symbol.Height / 2));
                Matrix transform = new Matrix();
                transform.RotateAt(rotation, rotationCenter);

                g.Transform = transform;

                if (symbolscale == 1f)
                {
                    g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));
                }
                else
                {
                    float width  = symbol.Width * symbolscale;
                    float height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                }

                g.Transform = startingTransform;
            }
            else
            {
                if (symbolscale == 1f)
                {
                    g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));
                }
                else
                {
                    float width  = symbol.Width * symbolscale;
                    float height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                }
            }
        }
        /// <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. 4
0
        private byte[] DrawImage()
        {
            // Determine barcode symbology
            BarcodeSymbology symbology     = BarcodeSymbology.Unknown;
            string           symbologyText = (string)GetCustomProperty("barcode:Symbology");

            symbology = (BarcodeSymbology)Enum.Parse(typeof(BarcodeSymbology), symbologyText);
            if (symbology != BarcodeSymbology.Unknown)
            {
                // Create draw object
                BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(symbology);

                // Get default metrics and override with values specified in CRI
                BarcodeMetrics metrics = drawObject.GetDefaultMetrics(
                    GetCustomPropertyInt32("barcode:MaximumBarHeight", 30));
                metrics.MinHeight =
                    GetCustomPropertyInt32("barcode:MinimumBarHeight", metrics.MinHeight);
                metrics.MinWidth =
                    GetCustomPropertyInt32("barcode:MinimumBarWidth", metrics.MinWidth);
                metrics.MaxWidth =
                    GetCustomPropertyInt32("barcode:MaximumBarWidth", metrics.MaxWidth);
                metrics.InterGlyphSpacing =
                    GetCustomPropertyInt32("barcode:InterGlyphSpacing", metrics.InterGlyphSpacing);

                // Get the text to render
                string textToRender = (string)GetCustomProperty("barcode:Text");

                // Determine available space for rendering
                int criWidth  = (int)(_cri.Width.ToInches() * DPI);
                int criHeight = (int)(_cri.Height.ToInches() * DPI);

                // Create bitmap of the appropriate size
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                    criWidth, criHeight, PixelFormat.Format32bppArgb);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    // Clear entire background
                    g.Clear(System.Drawing.Color.White);

                    // Get barcode image
                    System.Drawing.Image barcodeImage =
                        drawObject.Draw(textToRender, metrics);

                    // Centre the image
                    int x = (bmp.Width - barcodeImage.Width) / 2;
                    int y = (bmp.Height - barcodeImage.Height) / 2;
                    g.DrawImageUnscaled(barcodeImage, x, y);
                }

                // Create memory stream for new image
                using (MemoryStream stream = new MemoryStream())
                {
                    // Save image and setup CRI image
                    bmp.Save(stream, ImageFormat.Bmp);
                    return(stream.ToArray());
                }
            }
            return(null);
        }
Esempio n. 5
0
 private System.Drawing.Image CloneImage(System.Drawing.Image i)
 {
     System.Drawing.Bitmap   b = new System.Drawing.Bitmap(i.Width, i.Height);
     System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
     g.DrawImageUnscaled(i, 0, 0);
     g.Dispose();
     return(b);
 }
Esempio n. 6
0
        /// <summary>
        /// Renders a point to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="point">Point to render</param>
        /// <param name="symbol">Symbol to place over point</param>
        /// <param name="symbolscale">The amount that the symbol should be scaled. A scale of '1' equals to no scaling</param>
        /// <param name="offset">Symbol offset af scale=1</param>
        /// <param name="rotation">Symbol rotation in degrees</param>
        /// <param name="map">Map reference</param>
        public static void DrawPoint(System.Drawing.Graphics g, SharpMap.Geometries.Point point, System.Drawing.Bitmap symbol, float symbolscale, System.Drawing.PointF offset, float rotation, SharpMap.Map map)
        {
            if (point == null)
            {
                return;
            }
            if (symbol == null)             //We have no point style - Use a default symbol
            {
                symbol = defaultsymbol;
            }
            System.Drawing.PointF pp = SharpMap.Utilities.Transform.WorldtoMap(point, map);

            if (rotation != 0 && !float.IsNaN(rotation))
            {
                g.TranslateTransform(pp.X, pp.Y);
                g.RotateTransform(rotation);
                g.TranslateTransform(-symbol.Width / 2, -symbol.Height / 2);
                if (symbolscale == 1f)
                {
                    g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));
                }
                else
                {
                    float width  = symbol.Width * symbolscale;
                    float height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                }
                g.Transform = map.MapTransform;
            }
            else
            {
                if (symbolscale == 1f)
                {
                    g.DrawImageUnscaled(symbol, (int)(pp.X - symbol.Width / 2 + offset.X), (int)(pp.Y - symbol.Height / 2 + offset.Y));
                }
                else
                {
                    float width  = symbol.Width * symbolscale;
                    float height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, (int)pp.X - width / 2 + offset.X * symbolscale, (int)pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                }
            }
        }
Esempio n. 7
0
        public void ShowCaret(System.Drawing.Graphics CurGraphics)
        {
            //prntSome.printSome("ShowCaret");
            System.Int32 X = this.Caret.Pos.X;
            System.Int32 Y = this.Caret.Pos.Y;

            if (this.Caret.IsOff == true)
            {
                return;
            }

            // paint a rectangle over the cursor position
            CurGraphics.DrawImageUnscaled(
                this.Caret.Bitmap,
                X * (int)this.CharSize.Width,
                Y * (int)this.CharSize.Height);

            // if we don't have a char to redraw then leave
            if (this.CharGrid[Y][X] == '\0')
            {
                return;
            }

            CharAttribs CurAttribs = new CharAttribs();

            CurAttribs.UseAltColor = true;

            CurAttribs.GL = this.AttribGrid[Y][X].GL;
            CurAttribs.GR = this.AttribGrid[Y][X].GR;
            CurAttribs.GS = this.AttribGrid[Y][X].GS;

            if (this.AttribGrid[Y][X].UseAltBGColor == false)
            {
                CurAttribs.AltColor = this.BackColor;
            }
            else if (this.AttribGrid[Y][X].UseAltBGColor == true)
            {
                CurAttribs.AltColor = this.AttribGrid[Y][X].AltBGColor;
            }

            CurAttribs.IsUnderscored = this.AttribGrid[Y][X].IsUnderscored;
            CurAttribs.IsDECSG       = this.AttribGrid[Y][X].IsDECSG;

            // redispay the current char in the background colour
            this.ShowChar(
                CurGraphics,
                this.CharGrid[Y][X],
                Caret.Pos.Y * this.CharSize.Height,
                Caret.Pos.X * this.CharSize.Width,
                CurAttribs);
        }
        private static System.Drawing.Bitmap RotateImg(System.Drawing.Bitmap bmp, float angle)
        {
            angle = angle % 360;
            if (angle > 180)
            {
                angle -= 360;
            }
            float sin = (float)Math.Abs(Math.Sin(angle *
                                                 Math.PI / 180.0));                  // this function takes radians
            float cos          = (float)Math.Abs(Math.Cos(angle * Math.PI / 180.0)); // this one too
            float newImgWidth  = sin * bmp.Height + cos * bmp.Width;
            float newImgHeight = sin * bmp.Width + cos * bmp.Height;
            float originX      = 0f;
            float originY      = 0f;

            if (angle > 0)
            {
                if (angle <= 90)
                {
                    originX = sin * bmp.Height;
                }
                else
                {
                    originX = newImgWidth;
                    originY = newImgHeight - sin * bmp.Width;
                }
            }
            else
            {
                if (angle >= -90)
                {
                    originY = sin * bmp.Width;
                }
                else
                {
                    originX = newImgWidth - sin * bmp.Height;
                    originY = newImgHeight;
                }
            }
            System.Drawing.Bitmap newImg =
                new System.Drawing.Bitmap((int)newImgWidth, (int)newImgHeight);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(newImg);
            g.Clear(System.Drawing.Color.White);
            g.TranslateTransform(originX, originY); // offset the origin to our calculated values
            g.RotateTransform(angle);               // set up rotate
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.DrawImageUnscaled(bmp, 0, 0);         // draw the image at 0, 0
            g.Dispose();
            return(newImg);
        }
Esempio n. 9
0
        public unsafe void SaveImages()
        {
            fixed(byte *pImg = &this.file.image[0])
            {
                indexSubTableArray *subtableB = (indexSubTableArray *)(pImg + (uint)entry.offset + (uint)size.indexSubTableArrayOffset);
                indexSubTableArray *subtableM = subtableB + (uint)size.numberOfIndexSubTables;
                indexSubTableArray *subtable  = subtableB;
                indexSubHeader *    subheader;

                //-----
                System.Drawing.Bitmap   bmp;
                System.Drawing.Bitmap   bmp0 = new System.Drawing.Bitmap(300, 300);
                System.Drawing.Graphics g    = System.Drawing.Graphics.FromImage(bmp0);
                g.Clear(System.Drawing.Color.Gray);
                int x = 0, y = 0;

                //-----
                while (subtable < subtableM)
                {
                    subheader = (indexSubHeader *)((byte *)subtableB + (uint)subtable->additionalOffsetToIndexSubTable);
                    if ((ushort)subheader->indexFormat == 1 && (ushort)subheader->imageFormat == 7)
                    {
                        indexSubTable1 *table           = (indexSubTable1 *)subheader;
                        ULONG *         offset          = &table->offsetArray;
                        ULONG *         offsetM         = offset + ((ushort)subtable->lastGlyphIndex - (ushort)subtable->firstGlyphIndex + 1);
                        byte *          imageDataOffset = pImg + (uint)this.file.tables["EBDT"].offset + (uint)subheader->imageDataOffset;

                        while (offset < offsetM)
                        {
                            ebdtFormat7 *f7 = (ebdtFormat7 *)(imageDataOffset + (uint)*offset);
                            g.DrawImageUnscaled(bmp = f7->GetBitmap(), x, y);
                            bmp.Dispose();
                            offset++;
                            x += 10; if (x >= 300)
                            {
                                x = 0; y += 10;
                            }
                        }
                    }
                    subtable++;
                }
                //-----
                g.Dispose();
                System.Drawing.Bitmap bmp1 = afh.Drawing.BitmapEffect.Invert(bmp0);
                bmp0.Dispose();
                bmp1.Save(System.IO.Path.Combine(afh.Application.Path.ExecutableDirectory, "images\\" + this.Text + ".bmp"));
                bmp1.Dispose();
                //-----
            }
        }
Esempio n. 10
0
 private void newBufferImage()
 {
     System.Drawing.Bitmap   newimg = new System.Drawing.Bitmap(this.Size.Width, this.Size.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     System.Drawing.Graphics g      = System.Drawing.Graphics.FromImage(newimg);
     g.Clear(this.BackColor);
     if (this.imgbuf != null)
     {
         g.DrawImageUnscaled(this.imgbuf, 0, 0);
         this.imgbuf.Dispose();
     }
     if (this.graphbuf != null)
     {
         this.graphbuf.Dispose();
     }
     this.imgbuf   = newimg;
     this.graphbuf = g;
     this.OnBufferImageRenew();
 }
        public override void OnRender(System.Drawing.Graphics g)
        {
            try
            {
                if (myMap.Layers.Count == 0)
                {
                    base.OnRender(g);
                    return;
                }

                var right = m__mercatorProjection.FromPixelToLatLng(new GMap.NET.GPoint(m_gMapControl.Size.Width, 0), (int)m_gMapControl.Zoom);
                var left  = m__mercatorProjection.FromPixelToLatLng(new GMap.NET.GPoint(0, 0), (int)m_gMapControl.Zoom);

                var right1 = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(right.Lng, right.Lat), m_googleMapCoordinateTransformation.MathTransform);
                var left1  = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(left.Lng, left.Lat), m_googleMapCoordinateTransformation.MathTransform);

                myMap.Size = new System.Drawing.Size(m_gMapControl.Width, m_gMapControl.Height);

                myMap.Zoom = right1.X - left1.X;

                // 不是Center,具体怎样还没细看
                //var p = GoogleMapOffset.GetOffseted(m_gMapControl.CurrentPosition);
                var p = m_gMapControl.FromLocalToLatLng(m_gMapControl.Size.Width / 2, m_gMapControl.Size.Height / 2);

                var p1 = GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(p.Lng, p.Lat), m_googleMapCoordinateTransformation.MathTransform);

                myMap.Center = p1;

                var image = myMap.GetMap();
                g.DrawImageUnscaled(image, 0, 0);

                //var image = myMap.GetMap();
                //var x = m_gMapControl.FromLatLngToLocal(new GMap.NET.PointLatLng(myMap.Envelope.Top, myMap.Envelope.Left));
                //var y = m_gMapControl.FromLatLngToLocal(new GMap.NET.PointLatLng(myMap.Envelope.Bottom, myMap.Envelope.Right));
                //g.DrawImage(image, x.X, x.Y, y.X - x.X, y.Y - x.Y);
            }
            catch (Exception)
            {
            }
        }
Esempio n. 12
0
 public void DrawTo(System.Drawing.Graphics graphics, float x, float y)
 {
     graphics.DrawImageUnscaled(this.bmp, (int)x, (int)y);
 }
        private byte[] DrawImage()
        {
            // Determine barcode symbology
            BarcodeSymbology symbology     = BarcodeSymbology.Unknown;
            string           symbologyText = (string)GetCustomProperty("barcode:Symbology");

            symbology = (BarcodeSymbology)Enum.Parse(typeof(BarcodeSymbology), symbologyText);
            if (symbology != BarcodeSymbology.Unknown)
            {
                // Create draw object
                BarcodeDraw drawObject = BarcodeDrawFactory.GetSymbology(symbology);

                // Get default metrics and override with values specified in CRI
                // TODO: Need more elegant method for doing this...
                BarcodeMetrics metrics = drawObject.GetDefaultMetrics(30);
                metrics.Scale =
                    GetCustomPropertyInt32("barcode:Scale", metrics.Scale);

                BarcodeMetrics1d metrics1d = metrics as BarcodeMetrics1d;
                if (metrics1d != null)
                {
                    metrics1d.MaxHeight =
                        GetCustomPropertyInt32("barcode:MaximumBarHeight", metrics1d.MaxHeight);
                    metrics1d.MinHeight =
                        GetCustomPropertyInt32("barcode:MinimumBarHeight", metrics1d.MinHeight);
                    metrics1d.MinWidth =
                        GetCustomPropertyInt32("barcode:MinimumBarWidth", metrics1d.MinWidth);
                    metrics1d.MaxWidth =
                        GetCustomPropertyInt32("barcode:MaximumBarWidth", metrics1d.MaxWidth);
                    int interGlyphSpacing =
                        GetCustomPropertyInt32("barcode:InterGlyphSpacing", -1);
                    if (interGlyphSpacing >= 0)
                    {
                        metrics1d.InterGlyphSpacing = interGlyphSpacing;
                    }
                    metrics1d.RenderVertically =
                        GetCustomPropertyBool("barcode:RenderVertically", metrics1d.RenderVertically);
                }
                else if (symbology == BarcodeSymbology.CodeQr)
                {
                    BarcodeMetricsQr qrMetrics = (BarcodeMetricsQr)metrics;
                    qrMetrics.Version =
                        GetCustomPropertyInt32("barcode:QrVersion", qrMetrics.Version);
                    qrMetrics.EncodeMode = (QrEncodeMode)
                                           GetCustomPropertyInt32("barcode:QrEncodeMode", (int)qrMetrics.EncodeMode);
                    qrMetrics.ErrorCorrection = (QrErrorCorrection)
                                                GetCustomPropertyInt32("barcode:QrErrorCorrection", (int)qrMetrics.ErrorCorrection);
                }

                // Get the text to render
                string textToRender = (string)GetCustomProperty("barcode:Text");

                // Determine available space for rendering
                int criWidth  = (int)(_cri.Width.ToInches() * DPI);
                int criHeight = (int)(_cri.Height.ToInches() * DPI);

                // Create bitmap of the appropriate size
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                    criWidth, criHeight, PixelFormat.Format32bppArgb);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    // Clear entire background
                    g.Clear(System.Drawing.Color.White);

                    // Get barcode image
                    System.Drawing.Image barcodeImage =
                        drawObject.Draw(textToRender, metrics);

                    // Centre the image
                    int x = (bmp.Width - barcodeImage.Width) / 2;
                    int y = (bmp.Height - barcodeImage.Height) / 2;
                    g.DrawImageUnscaled(barcodeImage, x, y);
                }

                // Create memory stream for new image
                using (MemoryStream stream = new MemoryStream())
                {
                    // Save image and setup CRI image
                    bmp.Save(stream, ImageFormat.Bmp);
                    return(stream.ToArray());
                }
            }
            return(null);
        }
Esempio n. 14
0
        //return "0" for single face and "c"(cache) for multiple face
        //for multiple face, the face rectangles are stored in CCommon.cacheRects
        //CComon.cacheBm store the 24bit Bitmap for source image
        public static string FindFaceAndEyes(BitmapSource srcimage, out System.Drawing.Rectangle facerect, out System.Drawing.Rectangle[] eyesrect)
        {
            String faceFileName = AppDomain.CurrentDomain.BaseDirectory + "haarcascade_frontalface_alt2.xml";
            String eyeFileName  = AppDomain.CurrentDomain.BaseDirectory + "haarcascade_eye.xml";

            //working with gdi to get 24bit rgb image
            System.Drawing.Bitmap   bmtest   = CCommon.BitmapImage2Bitmap(srcimage);
            System.Drawing.Bitmap   bmsrc24  = new System.Drawing.Bitmap(bmtest.Width, bmtest.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            System.Drawing.Graphics gbmsrc24 = System.Drawing.Graphics.FromImage(bmsrc24);
            gbmsrc24.DrawImageUnscaled(bmtest, 0, 0);
            gbmsrc24.Dispose();
            bmtest.Dispose();
            bmtest = null;

            if (cacheBm != null)
            {
                cacheBm.Dispose();
            }
            cacheBm = (System.Drawing.Bitmap)bmsrc24.Clone();

            //we do scaling if the source is too large
            double scale = 1.0;

            if (bmsrc24.Height > 500)
            {
                scale = (double)500 / bmsrc24.Height;
            }

            System.Drawing.Bitmap bm = new System.Drawing.Bitmap((int)(bmsrc24.Width * scale),
                                                                 (int)(bmsrc24.Height * scale),
                                                                 System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            System.Drawing.Graphics gbm = System.Drawing.Graphics.FromImage(bm);

            //scale down the source image for face dection
            gbm.DrawImage(bmsrc24,
                          new System.Drawing.Rectangle(0, 0, bm.Width, bm.Height),
                          new System.Drawing.Rectangle(0, 0, bmsrc24.Width, bmsrc24.Height),
                          System.Drawing.GraphicsUnit.Pixel);
            gbm.Dispose();

            // bm.Save(AppDomain.CurrentDomain.BaseDirectory +"temp\\~bm.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
            //////////////////////////////////////////


            IntelImage _img = CDetectFace.CreateIntelImageFromBitmap(bm);

            //IntPtr p_face = CDetectFace.HistEqualize(_img);
            bm.Dispose();
            bm = null;
            string strindex = "";

            using (HaarClassifier haarface = new HaarClassifier(faceFileName))
                using (HaarClassifier haareye = new HaarClassifier(eyeFileName))
                {
                    var faces = haarface.DetectObjects(_img.IplImage());
                    // var faces = haarface.DetectObjects(p_face );
                    if (faces.Count > 0)
                    {
                        List <System.Drawing.Rectangle> facerects = new List <System.Drawing.Rectangle>();
                        for (int i = 0; i < faces.Count; i++)
                        {
                            var face = faces.ElementAt(i);
                            System.Drawing.Rectangle rt = new System.Drawing.Rectangle((int)(face.x / scale),
                                                                                       (int)(face.y / scale),
                                                                                       (int)(face.width / scale),
                                                                                       (int)(face.height / scale));
                            facerects.Add(rt);
                        }
                        cacheRects = facerects;

                        if (faces.Count > 1)
                        {
                            //clean up and return
                            eyesrect = null;
                            facerect = facerect = System.Drawing.Rectangle.Empty;

                            _img.Dispose();
                            bmsrc24.Dispose();
                            bmsrc24 = null;

                            return("c"); //cached
                        }
                    }
                    else
                    {
                        cacheRects.Clear();
                    }

                    //only handle 1 face
                    if (faces.Count == 1)
                    {
                        var face = faces.ElementAt(0);

                        facerect = new System.Drawing.Rectangle((int)(face.x / scale),
                                                                (int)(face.y / scale),
                                                                (int)(face.width / scale),
                                                                (int)(face.height / scale));

                        int x = facerect.X, y = facerect.Y, h0 = facerect.Height, w0 = facerect.Width;

                        //to handle oversize face area
                        double rescale = 1.0;
                        if (h0 > 300)
                        {
                            rescale = 300.0 / h0;
                        }

                        System.Drawing.Rectangle temprect = new System.Drawing.Rectangle(x, y, w0, 10 * h0 / 16);

                        System.Drawing.Bitmap bm_eyes = bmsrc24.cropAtRect(temprect);

                        bm_eyes.Save(AppDomain.CurrentDomain.BaseDirectory + "temp\\~eye.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                        IntelImage image_eyes = CDetectFace.CreateIntelImageFromBitmap(bm_eyes);

                        //resize eyes area for better detection
                        IntelImage image_eyes2X = new IntelImage((int)(image_eyes.IplImageStruc().width *2 * rescale),
                                                                 (int)(image_eyes.IplImageStruc().height *2 * rescale));
                        NativeMethods.CvResize(image_eyes.IplImage(), image_eyes2X.IplImage(), NativeMethods.CV_INTER_CUBIC);

                        IntPtr p_eq_img_eyes = CDetectFace.HistEqualize(image_eyes2X);

                        var eyes = haareye.DetectObjects(p_eq_img_eyes);

                        ////clean up
                        NativeMethods.cvReleaseImage(ref p_eq_img_eyes);
                        image_eyes.Dispose();
                        image_eyes = null;
                        bm_eyes.Dispose();

                        image_eyes2X.Dispose();
                        image_eyes2X = null;

                        if (eyes.Count > 0)
                        {
                            eyesrect = new System.Drawing.Rectangle[eyes.Count];

                            for (int i = 0; i < eyesrect.Length; i++)
                            {
                                var eye = eyes.ElementAt(i);

                                //note that we had scale the eyes area by 2, so we scale back
                                eyesrect[i] = new System.Drawing.Rectangle((int)(eye.x / (2 * rescale)),
                                                                           (int)(eye.y / (2 * rescale)),
                                                                           (int)(eye.width / (2 * rescale)),
                                                                           (int)(eye.height / (2 * rescale)));
                            }


                            int mineyesize = (h0 / 12);
                            int maxeyesize = (h0 / 3);
                            //sorting
                            var tempeyeslist = eyesrect.ToList();


                            //dist to center of face
                            //  <-1/2 w -->
                            //  |          |          |
                            //  |<-x ->o<d>|          |
                            //  |          |          |
                            //  |          |          |
                            //  |          |          |
                            // o=center of eye
                            // x= x dist to center of eye
                            // d= difference of 1/2 w and x
                            //  = distance of eye center to center of face
                            // the further this distance, the more likely it is an eye
                            int half_facewidth = facerect.Width / 2;
                            tempeyeslist = tempeyeslist.OrderByDescending(eye => Math.Abs(eye.X + eye.Width / 2 - (half_facewidth))).ToList();

                            //size: should be within min and max eye size
                            tempeyeslist = tempeyeslist.OrderByDescending(eye => (eye.Width > mineyesize)).ToList();
                            tempeyeslist = tempeyeslist.OrderByDescending(eye => (eye.Width < maxeyesize)).ToList();


                            eyesrect = tempeyeslist.ToArray();
                        }
                        else
                        {
                            eyesrect = null;
                        }
                    }
                    else
                    {
                        facerect = System.Drawing.Rectangle.Empty;
                        eyesrect = null;
                    }
                }

            //NativeMethods.cvReleaseImage(ref  p_face );

            _img.Dispose();

            bmsrc24.Dispose();
            bmsrc24 = null;

            return(strindex);
        }
        /// <summary> Retrieves the image stream for a certain map rectangle. </summary>
        /// <param name="left"> Left coordinates. </param>
        /// <param name="top"> Top coordinates. </param>
        /// <param name="right"> Right coordinates. </param>
        /// <param name="bottom"> Bottom coordinates. </param>
        /// <param name="width"> Width of the image. </param>
        /// <param name="height"> Height of the image. </param>
        /// <param name="border"> Border width. </param>
        /// <param name="mapObjects"> Set of map objects. </param>
        /// <returns> The image as a stream. </returns>
        public Stream GetStream(double left, double top, double right, double bottom, int width, int height, int border, out IEnumerable <IMapObject> mapObjects)
        {
            mapObjects = null;

            if (left >= minX && right <= maxX && top >= minY && bottom <= maxY && border <= 0)
            {
                return(GetStreamInternal(left, top, right, bottom, width, height, out mapObjects));
            }

            // request must be resized or clipped
            double leftResized, rightResized, topResized, bottomResized;

            // calculate resized bounds depending on border
            // the resize factor internally resizes requested tiles to avoid clipping problems
            if (border > 0)
            {
                double resize  = (double)border / width;
                double lWidth  = (right - left) * resize;
                double lHeight = (bottom - top) * resize;

                leftResized   = left - lWidth;
                rightResized  = right + lWidth;
                topResized    = top - lHeight;
                bottomResized = bottom + lHeight;
            }
            else
            {
                leftResized   = left;
                rightResized  = right;
                topResized    = top;
                bottomResized = bottom;
            }

            // calculate clipped bounds
            double leftClipped   = leftResized < minX ? minX : leftResized;
            double rightClipped  = rightResized > maxX ? maxX : rightResized;
            double topClipped    = topResized < minY ? minY : topResized;
            double bottomClipped = bottomResized > maxY ? maxY : bottomResized;

            // calculate corresponding pixel width and height
            //
            // TODO: There might be a deep zoom issue arising from using Math.Round, especially when clipping
            // is active. In this case , Math.Round changes the aspect ratio of the pixel rectangle significantly
            // on lower levels. Look at MapParam.FixMe that tries to handle aspect issues. Ignored for the moment.
            int widthClipped  = (int)Math.Round(width * (rightClipped - leftClipped) / (right - left));
            int heightClipped = (int)Math.Round(height * (bottomClipped - topClipped) / (bottom - top));

            if (widthClipped < 32 || heightClipped < 32)
            {
                // resulting image will be too small -> return empty image
                using (var bmp = new System.Drawing.Bitmap(width, height))
                {
                    return(SaveAndConvert(bmp));
                }
            }
            using (var stream = GetStreamInternal(leftClipped, topClipped, rightClipped, bottomClipped, widthClipped, heightClipped, out mapObjects))
            {
                // paste resized/clipped image on new image
                using (var img = System.Drawing.Image.FromStream(stream))
                {
                    using (var bmp = new System.Drawing.Bitmap(width, height))
                    {
                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                        {
                            double offsetX = (leftClipped - left) / (right - left) * width;
                            double offsetY = (bottomClipped - bottom) / (top - bottom) * height;

                            g.DrawImageUnscaled(img, (int)Math.Round(offsetX), (int)Math.Round(offsetY));
                        }

                        return(SaveAndConvert(bmp));
                    }
                }
            }
        }
Esempio n. 16
0
        public static string getExpertImage()
        {
            if (SessionClass.Flow.Count > 0)
            {
                System.Drawing.Bitmap   bm = new System.Drawing.Bitmap(400, SessionClass.Flow.Count * 90);
                System.Drawing.Graphics g  = System.Drawing.Graphics.FromImage(bm);
                g.Clear(System.Drawing.Color.White);
                int x = 100;
                int y = 10;
                System.Drawing.StringFormat f = new System.Drawing.StringFormat();
                f.Alignment     = System.Drawing.StringAlignment.Center;
                f.LineAlignment = System.Drawing.StringAlignment.Center;
                System.Drawing.Font font;
                System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Point(0, 40), new System.Drawing.Point(30, 130), System.Drawing.Color.GreenYellow, System.Drawing.Color.LemonChiffon);
                for (int i = 0; i < SessionClass.Flow.Count; i++)
                {
                    if (((Node)SessionClass.Flow[i]).type == 1)
                    {
                        font = new System.Drawing.Font("Arial Unicode MS", 9, System.Drawing.FontStyle.Regular);
                        g.DrawImageUnscaled(System.Drawing.Image.FromFile(HttpContext.Current.Request.MapPath("tskRect.png")), x - 3, y);
                        g.DrawString(((Node)SessionClass.Flow[i]).fromTitle.Substring(0, ((Node)SessionClass.Flow[i]).fromTitle.Length > 56 ? 56 : ((Node)SessionClass.Flow[i]).fromTitle.Length), font, System.Drawing.Brushes.Black, new System.Drawing.Rectangle(x + 35, y + 8, 170, 40), f);
                        y += 85;
                    }
                    else
                    {
                        font = new System.Drawing.Font("Arial Unicode MS", 10, System.Drawing.FontStyle.Regular);
                        g.DrawImageUnscaled(System.Drawing.Image.FromFile(HttpContext.Current.Request.MapPath("tskOval.png")), x, y);
                        g.DrawString(((Node)SessionClass.Flow[i]).fromTitle.Substring(0, ((Node)SessionClass.Flow[i]).fromTitle.Length > 52 ? 52 : ((Node)SessionClass.Flow[i]).fromTitle.Length), font, System.Drawing.Brushes.Black, new System.Drawing.Rectangle(x + 30, y + 6, 172, 40), f);
                        y += 85;
                    }
                    if (((Node)SessionClass.Flow[i]).from == -1)
                    {
                        break;
                    }
                }

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

                        g.DrawString(((Node)SessionClass.Flow[i - 1]).decision.Equals("True")?"Yes":"No", new System.Drawing.Font("Arial Unicode MS", 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, new System.Drawing.Point(205, y1 + 6));
                        if (((Node)SessionClass.Flow[i]).from == -1)
                        {
                            break;
                        }
                    }
                }
                string res = HttpContext.Current.Server.MapPath("Results") + "\\User" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".png";
                bm.Save(res, System.Drawing.Imaging.ImageFormat.Png);
                return("Results/" + res.Replace(HttpContext.Current.Server.MapPath("Results") + "\\", ""));
            }
            return("");
        }
Esempio n. 17
0
        } // End Function MapProjectPath

        public static void LocalizeSprites()
        {
            string strContent = System.IO.File.ReadAllText(MapProjectPath("~OpenIdSelector/js/openid-de.js"), System.Text.Encoding.UTF8);

            strContent = System.IO.File.ReadAllText(MapProjectPath("~OpenIdSelector/js/openid-en.js"), System.Text.Encoding.UTF8);

            cRootObject localizations = TrySerialize(strContent);

            int cntLarge = localizations.providers["providers_large"].Count;
            int cntSmall = localizations.providers["providers_small"].Count;

            // 100x60
            const int LARGE_PROVIDER_MAX_WIDTH  = 100;
            const int LARGE_PROVIDER_MAX_HEIGHT = 60;

            // 16x16
            const int SMALL_PROVIDER_MAX_WIDTH  = 20;
            const int SMALL_PROVIDER_MAX_HEIGHT = 20;

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                System.Math.Max(cntLarge * LARGE_PROVIDER_MAX_WIDTH, cntSmall * SMALL_PROVIDER_MAX_WIDTH)
                , LARGE_PROVIDER_MAX_HEIGHT + SMALL_PROVIDER_MAX_HEIGHT);

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


                int i = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, cProvider> provider in localizations.providers["providers_large"])
                {
                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(MapProjectPath("~OpenIdSelector/images.large/" + provider.Key + ".gif")))
                    {
                        g.DrawImageUnscaled(img, i * LARGE_PROVIDER_MAX_WIDTH + (LARGE_PROVIDER_MAX_WIDTH - img.Width) / 2, (LARGE_PROVIDER_MAX_HEIGHT - img.Height) / 2);
                    } // End Using img

                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(MapProjectPath("~OpenIdSelector/images.small/" + provider.Key + ".ico.png")))
                    {
                        g.DrawImageUnscaled(img, i * SMALL_PROVIDER_MAX_WIDTH + (SMALL_PROVIDER_MAX_WIDTH - img.Width) / 2
                                            , LARGE_PROVIDER_MAX_HEIGHT + (SMALL_PROVIDER_MAX_HEIGHT - img.Height) / 2);
                    } // End Using img

                    System.Console.WriteLine(provider.Key + ":");
                    System.Console.WriteLine(provider.Value.label);
                    System.Console.WriteLine(provider.Value.name);
                    System.Console.WriteLine(provider.Value.url);
                    ++i;
                } // Next provider

                // i = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, cProvider> provider in localizations.providers["providers_small"])
                {
                    using (System.Drawing.Image img = System.Drawing.Image.FromFile(MapProjectPath("~OpenIdSelector/images.small/" + provider.Key + ".ico.png")))
                    {
                        g.DrawImageUnscaled(img, i * SMALL_PROVIDER_MAX_WIDTH + (SMALL_PROVIDER_MAX_WIDTH - img.Width) / 2
                                            , LARGE_PROVIDER_MAX_HEIGHT + (SMALL_PROVIDER_MAX_HEIGHT - img.Height) / 2);
                    } // End Using img

                    System.Console.WriteLine(provider.Key + ":");
                    System.Console.WriteLine(provider.Value.label);
                    System.Console.WriteLine(provider.Value.name);
                    System.Console.WriteLine(provider.Value.url);
                    ++i;
                } // Next provider

                bmp.MakeTransparent(System.Drawing.Color.HotPink);


                string fn = MapProjectPath("~OpenIdSelector/images/openidfile.png");
                bmp.Save(fn, System.Drawing.Imaging.ImageFormat.Png);
            } // End Using g

            System.Console.WriteLine(localizations);
        } // End Sub LocalizeSprites
Esempio n. 18
0
        public void ShowChar(
            System.Drawing.Graphics CurGraphics,
            System.Char CurChar,
            System.Int32 Y,
            System.Int32 X,
            CharAttribs CurAttribs)
        {
            //prntSome.printSome("ShowChar");
            if (CurChar == '\0')
            {
                return;
            }

            System.Drawing.Color CurFGColor = System.Drawing.Color.White;
            System.Drawing.Color CurBGColor = System.Drawing.Color.Black;

            this.AssignColors(CurAttribs, ref CurFGColor, ref CurBGColor);

            if ((CurBGColor != this.BackColor && (this.Modes.Flags & uc_Mode.LightBackground) == 0) ||
                (CurBGColor != this.FGColor && (this.Modes.Flags & uc_Mode.LightBackground) > 0))
            {
                // Erase the current Character underneath the cursor postion
                this.EraseBuffer.Clear(CurBGColor);

                // paint a rectangle over the cursor position in the character's BGColor
                CurGraphics.DrawImageUnscaled(
                    this.EraseBitmap,
                    X,
                    Y);
            }

            if (CurAttribs.IsUnderscored)
            {
                CurGraphics.DrawLine(new System.Drawing.Pen(CurFGColor, 1),
                                     X, Y + this.UnderlinePos,
                                     X + this.CharSize.Width, Y + this.UnderlinePos);
            }

            /*VT220*/

            /*
             * if ((CurAttribs.IsDECSG == true) &&
             *  (CurChar == 'l' ||
             *   CurChar == 'q' ||
             *   CurChar == 'w' ||
             *   CurChar == 'k' ||
             *   CurChar == 'x' ||
             *   CurChar == 't' ||
             *   CurChar == 'n' ||
             *   CurChar == 'u' ||
             *   CurChar == 'm' ||
             *   CurChar == 'v' ||
             *   CurChar == 'j' ||
             *   CurChar == '`'))
             * {
             *  this.ShowSpecialChar (
             *      CurGraphics,
             *      CurChar,
             *      Y,
             *      X,
             *      CurFGColor,
             *      CurBGColor);
             *
             *  return;
             * }*/
            /**/
            //ANSI
            if ((CurAttribs.IsDECSG == true) &&
                (CurChar == 'Z' ||
                 CurChar == 'l' ||
                 CurChar == 'q' ||
                 CurChar == 'D' ||
                 CurChar == 'B' ||
                 CurChar == '?' ||
                 CurChar == '3' ||
                 CurChar == 'C' ||
                 CurChar == 'E' ||
                 CurChar == '4' ||
                 CurChar == '@' ||
                 CurChar == 'A' ||
                 CurChar == 'Y' ||
                 CurChar == '`'))
            {
                this.ShowSpecialChar(
                    CurGraphics,
                    CurChar,
                    Y,
                    X,
                    CurFGColor,
                    CurBGColor);

                return;
            }
            /**/
            //prntSome.add2stringrdb(CurChar.ToString());
            CurGraphics.DrawString(
                CurChar.ToString(),
                this.Font,
                new System.Drawing.SolidBrush(CurFGColor),
                X - this.DrawStringOffset.X,
                Y - this.DrawStringOffset.Y);
        }
Esempio n. 19
0
        public void ReloadCanvas(int id)
        {
            if (loading)
            {
                return;
            }
            if (!running)
            {
                canvasId = id;
                return;
            }
            Thread loadThread = new Thread(() =>
            {
                loading = true;
                Dispatcher.Invoke(() =>
                {
                    HideOverlay(true);
                    RemoveNameLabers();
                    OnResetPosition(null, null);
                    MainImageBorder.Visibility = Visibility.Hidden;
                    loadingSign.Visibility     = Visibility.Visible;
                    bitmap = null;
                    DataExchange.PushLoadingState(true);
                    loadingFailSign.Visibility = Visibility.Collapsed;
                });

                canvasId     = id;
                bool success = false;
                Logger.Info("Loading canvas {0} in PixelCanvas", id);

                System.Net.WebResponse response = null;
                System.IO.Stream responseStream = null;
                try
                {
                    System.Net.WebRequest request = System.Net.WebRequest.Create("https://pixelplace.io/canvas/" + id.ToString() + ".png");
                    response       = request.GetResponse();
                    responseStream = response.GetResponseStream();
                    using (var loadedBitmap = new System.Drawing.Bitmap(responseStream))
                    {
                        System.Drawing.Bitmap white = new System.Drawing.Bitmap(loadedBitmap.Width, loadedBitmap.Height);
                        using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(white))
                        {
                            gr.Clear(System.Drawing.Color.White);
                            gr.DrawImageUnscaled(loadedBitmap, new System.Drawing.Point(0, 0));
                        }
                        loadedBitmap.Dispose();
                        Dispatcher.Invoke(() => bitmap           = new WriteableBitmap(Helper.Convert(white)));
                        Dispatcher.Invoke(() => MainImage.Source = bitmap);
                    }
                    Dispatcher.Invoke(() => CreatePalette());
                    success = true;
                }
                catch (System.Net.WebException)
                {
                    Logger.Warning("Could not load canvas in pixelcanvas");
                    responseStream?.Dispose();
                }

                if (!success)
                {
                    Dispatcher.Invoke(() =>
                    {
                        bitmap = new WriteableBitmap(Helper.Convert(new System.Drawing.Bitmap(100, 100)));
                        loadingFailSign.Visibility = Visibility.Visible;
                    });
                }

                loading = false;
                Dispatcher.Invoke(() =>
                {
                    OnSaveRevertStateClick(null, null);
                    DataExchange.PushLoadingState(false);
                    MainImageBorder.Visibility = Visibility.Visible;
                    loadingSign.Visibility     = Visibility.Hidden;
                    HideOverlay(false);
                    if (firstLoad)
                    {
                        firstLoad = false;
                        if (firstLoadAction != null)
                        {
                            firstLoadAction();
                        }
                    }
                });
            });

            loadThread.Name         = "canvas loading thread";
            loadThread.IsBackground = true;
            loadThread.Start();
        }