static void Main(string[] args) { try { //TestProj4(); //TestPerformance(); //Console.ReadLine(); //TestVtc().Wait(); //ParseSQL(); //Current.Engine = new gView.GraphicsEngine.GdiPlus.GdiGraphicsEngine(96); Current.Engine = new gView.GraphicsEngine.Skia.SkiaGraphicsEngine(96); Current.Encoder = new GraphicsEngine.GdiPlus.GdiBitmapEncoding(); ////Current.Encoder = new GraphicsEngine.Skia.SkiaBitmapEncoding(); using (var bitmap = CreateImage(850, 600)) { using (var filteredBitmap = BaseFilter.ApplyFilter(bitmap, FilterImplementations.GrayscaleBT709)) { var start = DateTime.Now; SaveBitmap(filteredBitmap, "C:\\temp\\graphic.jpg"); Console.WriteLine($"Encoding Time: { (DateTime.Now - start).TotalMilliseconds }ms"); } } } catch (Exception ex) { Console.WriteLine("Exception: " + ex); } }
// Thread async public Task Render() { GraphicsEngine.Abstraction.IBitmap _filteredBitmap = null; try { if (_layer == null || _map == null || _cancelTracker == null) { return; } if (_layer.RasterClass.Polygon == null) { return; } IEnvelope env = _layer.RasterClass.Polygon.Envelope; double minx = env.minx, miny = env.miny, maxx = env.maxx, maxy = env.maxy; _map.World2Image(ref minx, ref miny); _map.World2Image(ref maxx, ref maxy); int iWidth = 0, iHeight = 0; int min_x = Math.Max(0, (int)Math.Min(minx, maxx) - 1); int min_y = Math.Max(0, (int)Math.Min(miny, maxy) - 1); int max_x = Math.Min(iWidth = _map.iWidth, (int)Math.Max(minx, maxx) + 1); int max_y = Math.Min(iHeight = _map.iHeight, (int)Math.Max(miny, maxy) + 1); using (var paintContext = await _layer.RasterClass.BeginPaint(_map.Display, _cancelTracker)) { if (_filter != FilterImplementations.Default) { _filteredBitmap = BaseFilter.ApplyFilter(paintContext.Bitmap, _filter); } if (paintContext.Bitmap == null && _filteredBitmap == null) { return; } //System.Windows.Forms.MessageBox.Show("begin"); double W = (_map.Envelope.maxx - _map.Envelope.minx); double H = (_map.Envelope.maxy - _map.Envelope.miny); double MinX = _map.Envelope.minx; double MinY = _map.Envelope.miny; //_lastRasterLayer = _layer; var canvas = _map.Display.Canvas; if (canvas == null) { return; } canvas.InterpolationMode = (GraphicsEngine.InterpolationMode)_interpolMethod; // Transformation berechnen GraphicsEngine.CanvasRectangleF rect; switch (canvas.InterpolationMode) { case GraphicsEngine.InterpolationMode.Bilinear: case GraphicsEngine.InterpolationMode.Bicubic: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width - 1f, paintContext.Bitmap.Height - 1f); break; case GraphicsEngine.InterpolationMode.NearestNeighbor: rect = new GraphicsEngine.CanvasRectangleF(-0.5f, -0.5f, paintContext.Bitmap.Width, paintContext.Bitmap.Height); //rect = new GraphicsEngine.CanvasRectangleF(0f, 0f, _layer.RasterClass.Bitmap.Width, _layer.RasterClass.Bitmap.Height); break; default: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width, paintContext.Bitmap.Height); break; } var points = new GraphicsEngine.CanvasPointF[3]; if (_layer.RasterClass is IRasterClass2) { IPoint p1 = ((IRasterClass2)_layer.RasterClass).PicPoint1; IPoint p2 = ((IRasterClass2)_layer.RasterClass).PicPoint2; IPoint p3 = ((IRasterClass2)_layer.RasterClass).PicPoint3; if (_map.Display.GeometricTransformer != null) { p1 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p1); p2 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p2); p3 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p3); } double X = p1.X, Y = p1.Y; _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = p2.X; Y = p2.Y; _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = p3.X; Y = p3.Y; _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); RoundGraphicPixelPoints(points); } else { double X1 = _layer.RasterClass.oX - _layer.RasterClass.dx1 / 2.0 - _layer.RasterClass.dy1 / 2.0; double Y1 = _layer.RasterClass.oY - _layer.RasterClass.dx2 / 2.0 - _layer.RasterClass.dy2 / 2.0; double X = X1; double Y = Y1; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = X1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx1; Y = Y1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = X1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy1; Y = Y1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); } if (_transColor.ToArgb() != System.Drawing.Color.Transparent.ToArgb()) { try { // kann OutOfMemoryException auslösen... paintContext.Bitmap.MakeTransparent(_transColor); } catch (Exception ex) { if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null) { await((IServiceMap)_map).MapServer.LogAsync( ((IServiceMap)_map).Name, "RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error, ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace); } if (_map != null) { if (_map != null) { _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex)); } } } } //var comQual = gr.CompositingQuality; //gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; float opaque = 1.0f - _transparency; canvas.DrawBitmap(_filteredBitmap ?? paintContext.Bitmap, points, rect, opacity: opaque); _map.FireRefreshMapView(); } } catch (Exception ex) { if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null) { await((IServiceMap)_map).MapServer.LogAsync( ((IServiceMap)_map).Name, "RenderRasterLayerThread:" + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error, ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace); } if (_map != null) { if (_map != null) { _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex)); } } } finally { if (_filteredBitmap != null) { _filteredBitmap.Dispose(); } } }
async public Task Request(IServiceRequestContext context) { if (context == null || context.ServiceRequest == null) { return; } if (_mapServer == null) { context.ServiceRequest.Response = "<FATALERROR>MapServer Object is not available!</FATALERROR>"; context.ServiceRequest.ResponseContentType = "text/xml"; return; } TileServiceMetadata metadata = await context.GetMetadtaProviderAsync(_metaprovider) as TileServiceMetadata; if (metadata == null || metadata.Use == false) { context.ServiceRequest.Response = "<ERROR>Service is not used with Tile Service</ERROR>"; context.ServiceRequest.ResponseContentType = "text/xml"; return; } string request = context.ServiceRequest.Request; //_mapServer.Log("WMTSRequest", loggingMethod.request_detail, request); if (request.Contains("=")) // QueryString { QueryString queryString = new QueryString(request); if (queryString.HasValue("service", "wmts") && queryString.HasValue("request", "getcapabilities") && queryString.HasValue("version", "1.0.0")) { WmtsCapabilities100(context, metadata); return; } else if (queryString.HasValue("service", "wmts") && queryString.HasValue("request", "getmetadata") && queryString.HasValue("version", "1.0.0")) { WmtsMetadata100(context, metadata); return; } } string[] args = request.Split('/'); if (args.Length == 7) { string cacheFormat = args[0].ToLower(); if (args[1].ToLower() != "ul" && args[1].ToLower() != "ll") { throw new ArgumentException(); } int epsg = int.Parse(args[2]); string style = args[3].ToLower(); double scale = GetScale(metadata, args[4]); // double.Parse(args[4].Replace(",", "."), _nhi); int row = int.Parse(args[5]); int col = int.Parse(args[6].Split('.')[0]); string format = ".png"; if (args[6].ToLower().EndsWith(".jpg") || args[6].ToLower().EndsWith(".jpeg")) { format = ".jpg"; } byte[] imageData = null; if (scale > 0) { if (cacheFormat == "compact") { imageData = await GetCompactTile(context, metadata, epsg, scale, row, col, format, (args[1].ToLower() == "ul" ? GridOrientation.UpperLeft : GridOrientation.LowerLeft)); } else { imageData = await GetTile(context, metadata, epsg, scale, row, col, format, (args[1].ToLower() == "ul" ? GridOrientation.UpperLeft : GridOrientation.LowerLeft)); } if (style != "default" && imageData != null) { //throw new NotImplementedException("Not in .Net Standard..."); FilterImplementations filter; if (Enum.TryParse <FilterImplementations>(style, true, out filter)) { imageData = BaseFilter.ApplyFilter(imageData, filter, format == ".png" ? ImageFormat.Png : ImageFormat.Jpeg); } } } context.ServiceRequest.ResponseContentType = $"image/{ format.Substring(1) }"; context.ServiceRequest.ResponseExpries = DateTime.UtcNow.AddDays(7); context.ServiceRequest.Response = imageData ?? _emptyPic; } return; }