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); } }
public bool Merge(GraphicsEngine.Abstraction.IBitmap bitmap, IDisplay display) { try { int iWidth = bitmap.Width; int iHeight = bitmap.Height; using (var canvas = bitmap.CreateCanvas()) { canvas.CompositingMode = GraphicsEngine.CompositingMode.SourceOver; foreach (GeorefBitmap geoBmp in _picList) { if (geoBmp == null || geoBmp.Bitmap == null) { continue; } if (bitmap != geoBmp.Bitmap) { if (geoBmp.Envelope != null) { double x0, y0, x1, y1, x2, y2; gView.Framework.Geometry.IGeometry geom = gView.Framework.Geometry.GeometricTransformerFactory.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(display.Map, false); d.Limit = d.Envelope = geoBmp.Envelope; d.iWidth = geoBmp.Bitmap.Width; d.iHeight = geoBmp.Bitmap.Height; d.SpatialReference = geoBmp.SpatialReference; Resample(bitmap, display, geoBmp.Bitmap, d); 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); GraphicsEngine.CanvasPointF[] points = { new GraphicsEngine.CanvasPointF((float)x0, (float)y0), new GraphicsEngine.CanvasPointF((float)x1, (float)y1), new GraphicsEngine.CanvasPointF((float)x2, (float)y2) }; canvas.DrawBitmap(geoBmp.Bitmap, points, new GraphicsEngine.CanvasRectangleF(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height), opacity: geoBmp.Opacity); } else { canvas.DrawBitmap(geoBmp.Bitmap, new GraphicsEngine.CanvasRectangle(0, 0, iWidth, iHeight), new GraphicsEngine.CanvasRectangle(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height), opacity: geoBmp.Opacity); } } } } if (_scale > 0) { Scalebar bar = new Scalebar(_scale, m_dpi); bar.Create(bitmap, bitmap.Width - (int)(50 * m_dpi / 96.0) - bar.ScaleBarWidth, bitmap.Height - (int)(32 * m_dpi / 96.0)); } return(true); } catch (Exception ex) { _errMsg = ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace; return(false); } }