Пример #1
0
        private static PointN ToPoint(gView.Framework.Geometry.IPoint point)
        {
            if (point == null)
            {
                return(null);
            }

            PointN p = new PointN();

            p.X = point.X;
            p.Y = point.Y;
            if (point.Z != 0.0)
            {
                p.Z = point.Z;
            }

            return(p);
        }
Пример #2
0
        private static gView.Framework.Geometry.IRing ToRing(Ring ring, ref bool complex)
        {
            gView.Framework.Geometry.Ring r = new gView.Framework.Geometry.Ring();
            if (ring != null && ring.PointArray != null)
            {
                foreach (Point point in ring.PointArray)
                {
                    if (point is PointN)
                    {
                        r.AddPoint(ToPoint((PointN)point));
                    }
                }
            }
            else if (ring != null && ring.SegmentArray != null)
            {
                complex = true;
                foreach (Segment segment in ring.SegmentArray)
                {
                    #region Line
                    if (segment is Line &&
                        (((Line)segment).FromPoint is PointN &&
                         ((Line)segment).ToPoint is PointN))
                    {
                        gView.Framework.Geometry.IPoint p1 = ToPoint((PointN)((Line)segment).FromPoint);
                        gView.Framework.Geometry.IPoint p2 = ToPoint((PointN)((Line)segment).ToPoint);

                        if (r.PointCount == 0)
                        {
                            r.AddPoint(p1);
                            r.AddPoint(p2);
                        }
                        else
                        {
                            if (r[r.PointCount - 1].Equals(p1))
                            {
                                r.AddPoint(p2);
                            }
                            else
                            {
                                r.AddPoint(p1);
                                r.AddPoint(p2);
                            }
                        }
                    }
                    #endregion
                    #region CircularArc
                    else if (segment is CircularArc &&
                             (((CircularArc)segment).FromPoint is PointN &&
                              ((CircularArc)segment).ToPoint is PointN))
                    {
                        gView.Framework.Geometry.IPoint p1 = ToPoint((PointN)((CircularArc)segment).FromPoint);
                        gView.Framework.Geometry.IPoint p2 = ToPoint((PointN)((CircularArc)segment).ToPoint);

                        if (r.PointCount == 0)
                        {
                            r.AddPoint(p1);
                            r.AddPoint(p2);
                        }
                        else
                        {
                            if (r[r.PointCount - 1].Equals(p1))
                            {
                                r.AddPoint(p2);
                            }
                            else
                            {
                                r.AddPoint(p1);
                                r.AddPoint(p2);
                            }
                        }
                    }
                    #endregion
                }
            }
            return(r);
        }
Пример #3
0
        private static gView.Framework.Geometry.IPath ToPath(Path path, ref bool complex)
        {
            gView.Framework.Geometry.Path p = new gView.Framework.Geometry.Path();
            if (path != null && path.PointArray != null)
            {
                foreach (Point point in path.PointArray)
                {
                    if (point is PointN)
                    {
                        p.AddPoint(ToPoint((PointN)point));
                    }
                }
            }
            else if (path != null && path.SegmentArray != null)
            {
                complex = true;
                foreach (Segment segment in path.SegmentArray)
                {
                    #region Line
                    if (segment is Line &&
                        (((Line)segment).FromPoint is PointN &&
                         ((Line)segment).ToPoint is PointN))
                    {
                        gView.Framework.Geometry.IPoint p1 = ToPoint((PointN)((Line)segment).FromPoint);
                        gView.Framework.Geometry.IPoint p2 = ToPoint((PointN)((Line)segment).ToPoint);

                        if (p.PointCount == 0)
                        {
                            p.AddPoint(p1);
                            p.AddPoint(p2);
                        }
                        else
                        {
                            if (p[p.PointCount - 1].Equals(p1))
                            {
                                p.AddPoint(p2);
                            }
                            else
                            {
                                p.AddPoint(p1);
                                p.AddPoint(p2);
                            }
                        }
                    }
                    #endregion
                    #region CircularArc
                    else if (segment is CircularArc &&
                             (((CircularArc)segment).FromPoint is PointN &&
                              ((CircularArc)segment).ToPoint is PointN))
                    {
                        gView.Framework.Geometry.IPoint p1 = ToPoint((PointN)((CircularArc)segment).FromPoint);
                        gView.Framework.Geometry.IPoint p2 = ToPoint((PointN)((CircularArc)segment).ToPoint);

                        if (p.PointCount == 0)
                        {
                            p.AddPoint(p1);
                            p.AddPoint(p2);
                        }
                        else
                        {
                            if (p[p.PointCount - 1].Equals(p1))
                            {
                                p.AddPoint(p2);
                            }
                            else
                            {
                                p.AddPoint(p1);
                                p.AddPoint(p2);
                            }
                        }
                    }
                    #endregion
                }
            }
            return(p);
        }
Пример #4
0
        public static void Resample(Bitmap dest, IDisplay destDisplay, Bitmap source, IDisplay sourceDisplay)
        {
            BitmapData destData = null, sourceData = null;

            gView.Framework.Geometry.GeometricTransformer transformer = new gView.Framework.Geometry.GeometricTransformer();

            try
            {
                //transformer.FromSpatialReference = sourceDisplay.SpatialReference;
                //transformer.ToSpatialReference = destDisplay.SpatialReference;
                transformer.SetSpatialReferences(sourceDisplay.SpatialReference, destDisplay.SpatialReference);

                destData   = dest.LockBits(new Rectangle(0, 0, dest.Width, dest.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                sourceData = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

                int sWidth = source.Width, sHeight = source.Height;
                int dWidth = dest.Width, dHeight = dest.Height;

                unsafe
                {
                    byte *ptr = (byte *)destData.Scan0;

                    for (int y = 0; y < dHeight; y++)
                    {
                        for (int x = 0; x < dWidth; x++)
                        {
                            double xx = x, yy = y;
                            destDisplay.Image2World(ref xx, ref yy);
                            gView.Framework.Geometry.IPoint point = (gView.Framework.Geometry.IPoint)transformer.InvTransform2D(new gView.Framework.Geometry.Point(xx, yy));
                            xx = point.X; yy = point.Y;
                            sourceDisplay.World2Image(ref xx, ref yy);

                            int x_ = (int)xx, y_ = (int)yy;
                            if (x_ >= 0 && x_ < sWidth &&
                                y_ >= 0 && y_ < sHeight)
                            {
                                byte *p = (byte *)sourceData.Scan0;
                                p += (y_ * destData.Stride + x_ * 4);

                                if (p[3] != 0) // Transparenz!!!
                                {
                                    ptr[0] = p[0];
                                    ptr[1] = p[1];
                                    ptr[2] = p[2];
                                    ptr[3] = p[3];
                                }
                            }

                            ptr += 4;
                        }
                        ptr += destData.Stride - destData.Width * 4;
                    }
                }
            }
            catch { }
            finally
            {
                transformer.Release();
                if (destData != null)
                {
                    dest.UnlockBits(destData);
                }
                if (sourceData != null)
                {
                    source.UnlockBits(sourceData);
                }
            }
        }
Пример #5
0
        public bool Merge(Bitmap image, IDisplay display)
        {
            try
            {
                int iWidth  = image.Width;
                int iHeight = image.Height;

                using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(image))
                {
                    gr.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                    foreach (GeorefBitmap geoBmp in m_picList)
                    {
                        if (geoBmp == null || geoBmp.Bitmap == null)
                        {
                            continue;
                        }
                        if (image != geoBmp.Bitmap)
                        {
                            if (geoBmp.Envelope != null)
                            {
                                double x0, y0, x1, y1, x2, y2;
                                gView.Framework.Geometry.IGeometry geom = gView.Framework.Geometry.GeometricTransformer.Transform2D(geoBmp.Envelope, geoBmp.SpatialReference, display.SpatialReference);
                                if (geom is gView.Framework.Geometry.IPolygon)
                                {
                                    gView.Framework.Geometry.IRing ring = ((gView.Framework.Geometry.IPolygon)geom)[0];

                                    x0 = ring[1].X; y0 = ring[1].Y;
                                    x1 = ring[2].X; y1 = ring[2].Y;
                                    x2 = ring[0].X; y2 = ring[0].Y;

                                    /////////////////////////////////////////////////////////
                                    Display d = new Display(false);
                                    d.Limit            = d.Envelope = geoBmp.Envelope;
                                    d.iWidth           = geoBmp.Bitmap.Width;
                                    d.iHeight          = geoBmp.Bitmap.Height;
                                    d.SpatialReference = geoBmp.SpatialReference;
                                    Resample(image, display, geoBmp.Bitmap, d);
                                    continue;

                                    gView.Framework.Geometry.GeometricTransformer transformer = new gView.Framework.Geometry.GeometricTransformer();
                                    //transformer.FromSpatialReference = geoBmp.SpatialReference;
                                    //transformer.ToSpatialReference = display.SpatialReference;
                                    transformer.SetSpatialReferences(geoBmp.SpatialReference, display.SpatialReference);

                                    for (int y = 0; y < image.Height; y++)
                                    {
                                        for (int x = 0; x < image.Width; x++)
                                        {
                                            double xx = x, yy = y;
                                            display.Image2World(ref xx, ref yy);
                                            gView.Framework.Geometry.IPoint point = (gView.Framework.Geometry.IPoint)transformer.InvTransform2D(new gView.Framework.Geometry.Point(xx, yy));
                                            xx = point.X; yy = point.Y;
                                            d.World2Image(ref xx, ref yy);
                                            try
                                            {
                                                int x_ = (int)xx, y_ = (int)yy;
                                                if (x_ >= 0 && y_ < geoBmp.Bitmap.Width &&
                                                    y_ > 0 && y_ < geoBmp.Bitmap.Height)
                                                {
                                                    image.SetPixel(x, y, geoBmp.Bitmap.GetPixel(x_, y_));
                                                }
                                            }
                                            catch { }
                                        }
                                    }
                                    transformer.Release();
                                    continue;
                                    //////////////////////////////////////////////////////////
                                }
                                else
                                {
                                    x0 = geoBmp.Envelope.minx; y0 = geoBmp.Envelope.maxy;
                                    x1 = geoBmp.Envelope.maxx; y1 = geoBmp.Envelope.maxy;
                                    x2 = geoBmp.Envelope.minx; y2 = geoBmp.Envelope.miny;
                                }

                                display.World2Image(ref x0, ref y0);
                                display.World2Image(ref x1, ref y1);
                                display.World2Image(ref x2, ref y2);

                                PointF[] points =
                                {
                                    new PointF((float)x0, (float)y0),
                                    new PointF((float)x1, (float)y1),
                                    new PointF((float)x2, (float)y2)
                                };

                                if (geoBmp.Opacity >= 0 && geoBmp.Opacity < 1.0)
                                {
                                    float[][] ptsArray =
                                    {
                                        new float[] { 1, 0, 0,              0, 0 },
                                        new float[] { 0, 1, 0,              0, 0 },
                                        new float[] { 0, 0, 1,              0, 0 },
                                        new float[] { 0, 0, 0, geoBmp.Opacity, 0 },
                                        new float[] { 0, 0, 0,              0, 1 }
                                    };

                                    System.Drawing.Imaging.ColorMatrix     clrMatrix     = new System.Drawing.Imaging.ColorMatrix(ptsArray);
                                    System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes();
                                    imgAttributes.SetColorMatrix(clrMatrix,
                                                                 System.Drawing.Imaging.ColorMatrixFlag.Default,
                                                                 System.Drawing.Imaging.ColorAdjustType.Bitmap);

                                    // Bitmap "kopieren", sonst kann es Out Of Memory Exceptions kommen!!!
                                    using (Bitmap bm_ = new Bitmap(geoBmp.Bitmap.Width, geoBmp.Bitmap.Height, NonIndedexedPixelFormat(geoBmp)))
                                    {
                                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm_))
                                        {
                                            g.DrawImage(geoBmp.Bitmap, new Point(0, 0));
                                            g.Dispose();
                                        }
                                        gr.DrawImage(bm_,
                                                     points,
                                                     new RectangleF(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                     GraphicsUnit.Pixel, imgAttributes);
                                        bm_.Dispose();
                                    }
                                }
                                else
                                {
                                    gr.DrawImage(geoBmp.Bitmap,
                                                 points,
                                                 new RectangleF(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                 GraphicsUnit.Pixel);
                                }
                            }
                            else
                            {
                                if (geoBmp.Opacity >= 0 && geoBmp.Opacity < 1.0)
                                {
                                    float[][] ptsArray =
                                    {
                                        new float[] { 1, 0, 0,              0, 0 },
                                        new float[] { 0, 1, 0,              0, 0 },
                                        new float[] { 0, 0, 1,              0, 0 },
                                        new float[] { 0, 0, 0, geoBmp.Opacity, 0 },
                                        new float[] { 0, 0, 0,              0, 1 }
                                    };

                                    System.Drawing.Imaging.ColorMatrix     clrMatrix     = new System.Drawing.Imaging.ColorMatrix(ptsArray);
                                    System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes();
                                    imgAttributes.SetColorMatrix(clrMatrix,
                                                                 System.Drawing.Imaging.ColorMatrixFlag.Default,
                                                                 System.Drawing.Imaging.ColorAdjustType.Bitmap);

                                    // Bitmap "kopieren", sonst kann es Out Of Memory Exceptions kommen!!!
                                    using (Bitmap bm_ = new Bitmap(geoBmp.Bitmap.Width, geoBmp.Bitmap.Height, NonIndedexedPixelFormat(geoBmp)))
                                    {
                                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bm_))
                                        {
                                            g.DrawImage(geoBmp.Bitmap, new Point(0, 0));
                                            g.Dispose();
                                        }
                                        gr.DrawImage(bm_,
                                                     new Rectangle(0, 0, iWidth, iHeight),
                                                     0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height,
                                                     GraphicsUnit.Pixel,
                                                     imgAttributes);
                                        bm_.Dispose();
                                    }
                                }
                                else
                                {
                                    gr.DrawImage(geoBmp.Bitmap,
                                                 new Rectangle(0, 0, iWidth, iHeight),
                                                 new Rectangle(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                 GraphicsUnit.Pixel);
                                }
                            }
                        }
                    }
                    gr.Dispose();
                }

                if (m_scale > 0)
                {
                    scalebar bar = new scalebar(m_scale, m_dpi);
                    bar.Create(ref image, image.Width - (int)(50 * m_dpi / 96.0) - bar.ScaleBarWidth, image.Height - (int)(32 * m_dpi / 96.0));
                }
                return(true);
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace;
                return(false);
            }
        }
Пример #6
0
        public static void Resample(GraphicsEngine.Abstraction.IBitmap dest,
                                    IDisplay destDisplay,
                                    GraphicsEngine.Abstraction.IBitmap source,
                                    IDisplay sourceDisplay)
        {
            GraphicsEngine.BitmapPixelData destData = null, sourceData = null;
            using (var transformer = gView.Framework.Geometry.GeometricTransformerFactory.Create())
            {
                try
                {
                    transformer.SetSpatialReferences(sourceDisplay.SpatialReference, destDisplay.SpatialReference);

                    destData   = dest.LockBitmapPixelData(GraphicsEngine.BitmapLockMode.WriteOnly, GraphicsEngine.PixelFormat.Rgba32);
                    sourceData = source.LockBitmapPixelData(GraphicsEngine.BitmapLockMode.ReadOnly, GraphicsEngine.PixelFormat.Rgba32);

                    int sWidth = source.Width, sHeight = source.Height;
                    int dWidth = dest.Width, dHeight = dest.Height;

                    unsafe
                    {
                        byte *ptr = (byte *)destData.Scan0;

                        for (int y = 0; y < dHeight; y++)
                        {
                            for (int x = 0; x < dWidth; x++)
                            {
                                double xx = x, yy = y;
                                destDisplay.Image2World(ref xx, ref yy);
                                gView.Framework.Geometry.IPoint point = (gView.Framework.Geometry.IPoint)transformer.InvTransform2D(new gView.Framework.Geometry.Point(xx, yy));
                                xx = point.X; yy = point.Y;
                                sourceDisplay.World2Image(ref xx, ref yy);

                                int x_ = (int)xx, y_ = (int)yy;
                                if (x_ >= 0 && x_ < sWidth &&
                                    y_ >= 0 && y_ < sHeight)
                                {
                                    byte *p = (byte *)sourceData.Scan0;
                                    p += (y_ * destData.Stride + x_ * 4);

                                    if (p[3] != 0) // Transparenz!!!
                                    {
                                        ptr[0] = p[0];
                                        ptr[1] = p[1];
                                        ptr[2] = p[2];
                                        ptr[3] = p[3];
                                    }
                                }

                                ptr += 4;
                            }
                            ptr += destData.Stride - destData.Width * 4;
                        }
                    }
                }
                catch { }
                finally
                {
                    if (destData != null)
                    {
                        dest.UnlockBitmapPixelData(destData);
                    }

                    if (sourceData != null)
                    {
                        source.UnlockBitmapPixelData(sourceData);
                    }
                }
            }
        }