Пример #1
0
        public Bitmap Create(HexContent item)
        {
            SKBitmap background  = _resRepo.GetImage(item.BackgroundImageId);
            SKBitmap finishedHex = new SKBitmap(background.Width, background.Height);

            SKCanvas canvas = new SKCanvas(finishedHex);

            canvas.DrawBitmap(background, 0, 0);

            var terrain = _resRepo.GetImage(item.TerrainImageId);

            if (terrain != null)
            {
                canvas.DrawBitmap(terrain, 0, 0);
            }
            var vegetation = _resRepo.GetImage(item.VegetationImageId);

            if (vegetation != null)
            {
                canvas.DrawBitmap(vegetation, 0, 0);
            }
            var feature = _resRepo.GetImage(item.FeatureImageId);

            if (feature != null)
            {
                canvas.DrawBitmap(feature, 0, 0);
            }

            return(finishedHex.ToBitmap());
        }
Пример #2
0
        public void SetLegendImage(KSeries series)
        {
            Image sdImage;
            int   height = button.Font.Height; const int width = 50; const int padding = 0; const int frame = 3; const int left = 0;
            int   thickness = (series.lineStyle == KLineStyle.Thick) ? 3 : (series.lineMode == KLineMode.Line) ? 1 : (height - 2 * frame - 1);
            int   framedH = thickness + 2 * frame; int framedY = (height - 2 * padding - framedH) / 2;
            int   framedW = width - 2 * padding; int framedX = left + padding;

            using (SKBitmap skBitmap = new SKBitmap(left + width, height))
                using (SKCanvas skCanvas = new SKCanvas(skBitmap))
                    using (SKPaint back = new SKPaint {
                        Style = SKPaintStyle.Fill, Color = new SKColor(backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A)
                    })
                        using (SKPaint white = new SKPaint {
                            Style = SKPaintStyle.Fill, Color = new SKColor(255, 255, 255, 255)
                        })
                            using (SKPaint color = new SKPaint {
                                Style = SKPaintStyle.Fill, Color = series.color
                            }) {
                                skCanvas.DrawRect(new SKRect(0, 0, left + width, height), back);
                                if (series.visible)
                                {
                                    skCanvas.DrawRect(new SKRect(framedX, framedY, framedX + framedW, framedY + framedH), white);
                                    skCanvas.DrawRect(new SKRect(framedX + frame, framedY + frame, framedX + framedW - frame, framedY + frame + thickness), color);
                                }
                                sdImage = skBitmap.ToBitmap();
                            }
            this.button.Image    = sdImage;
            this.button.AutoSize = false;
            this.button.Size     = this.button.Image.Size;
        }
Пример #3
0
        public void printThread(SKBitmap toPrint)
        {
            try
            {
                var context = global::Android.App.Application.Context;

                Printer printer = new Printer();

                string[] models = new string[6];
                models[0] = PrinterInfo.Model.PtP950nw.ToString();
                models[1] = PrinterInfo.Model.PtP950nw.ToString().Replace("_", "-");
                models[2] = "PtP950nw";
                models[3] = "PTP950NW";
                models[4] = "PT-P950NW";
                models[5] = "Pt-P950nw";

                NetPrinter[] printers = new NetPrinter[0];// printer.GetNetPrinters(models);

                PrinterInfo printInfo = new PrinterInfo();
                printInfo.PrinterModel = PrinterInfo.Model.PtP950nw;
                printInfo.Port         = PrinterInfo.PortEnum.Net;

                if (printers.Length == 0)
                {
                    printInfo.IpAddress = "192.168.43.126";
                }
                else
                {
                    printInfo.IpAddress = printers[0].IpAddress;
                }

                printInfo.PaperSize     = PrinterInfo.PaperSizeEnum.Custom;
                printInfo.PaperPosition = PrinterInfo.AlignEnum.Center;
                printInfo.Orientation   = PrinterInfo.OrientationEnum.Landscape;

                printInfo.LabelNameIndex = LabelInfo.PT.W36.Ordinal();
                printInfo.IsAutoCut      = true;
                printInfo.IsCutAtEnd     = true;
                printInfo.IsHalfCut      = true;

                printer.SetPrinterInfo(printInfo);

                printer.StartCommunication();

                using (Bitmap bmp = toPrint.ToBitmap())
                {
                    PrinterStatus status = printer.PrintImage(bmp);

                    bmp.Recycle();
                }

                printer.EndCommunication();
            }
            catch (Exception ex)
            {
            }
        }
Пример #4
0
 protected override Android.Graphics.Drawables.Drawable GetIconDrawable(FileImageSource icon)
 {
     if (icon.File.StartsWith("svg:"))
     {
         string   resourceid = icon.File.Replace("svg:", "");
         SKBitmap skBitmap   = SvgIcon.GetSvgBitmap(resourceid, 100, 100, new Xamarin.Forms.Color());
         return(new BitmapDrawable(context.Resources, skBitmap.ToBitmap()));
     }
     else
     {
         return(base.GetIconDrawable(icon));
     }
 }
        private async Task <Bitmap> GenerateBlendedCAMImage(CAM cam, SKColor color)
        {
            // Cancel the previous blending task if there is one
            cancellationTokenSource?.Cancel();

            cancellationTokenSource = new CancellationTokenSource();

            // Dispose of previous blended image
            blendedImage?.Dispose();

            SKBitmap colorMap = await ImageProcessorRunner.GetCAMColorMapTask(
                cam,
                color,
                originalXRay.Width,
                originalXRay.Height,
                cancellationTokenSource.Token
                );

            SKBitmap input           = originalXRay.ToSKBitmap();
            SKBitmap blendedSKBitmap = await ImageProcessorRunner.GetOverlayImageTask(
                input,
                colorMap,
                cancellationTokenSource.Token
                );

            // Dispose of temporary SKBitmap
            input.Dispose();

            Bitmap blendedBitmap = blendedSKBitmap.ToBitmap();

            // Cleanup the intermediate bitmaps
            colorMap?.Dispose();
            blendedSKBitmap?.Dispose();

            return(blendedBitmap);
        }
Пример #6
0
        private async Task HandleGroundOverlayForTile(TileInfo tileInfo)
        {
            if (SharedOverlay.IsVisible)
            {
                int       virtualTileSize = Extensions.SKMapExtensions.MercatorMapSize >> tileInfo.Zoom;
                int       xPixelsStart    = tileInfo.X * virtualTileSize;
                int       yPixelsStart    = tileInfo.Y * virtualTileSize;
                double    zoomScale       = SKMapCanvas.MapTileSize / (double)virtualTileSize;
                Rectangle mercatorSpan    = new Rectangle(xPixelsStart, yPixelsStart, virtualTileSize, virtualTileSize);
                SKMapSpan tileSpan        = mercatorSpan.ToGps();

                if (tileSpan.FastIntersects(SharedOverlay.GpsBounds))
                {
                    SKBitmap         bitmap                  = DrawTileToBitmap(tileSpan, zoomScale);
                    BitmapDescriptor bitmapDescriptor        = BitmapDescriptorFactory.FromBitmap(bitmap.ToBitmap());
                    TaskCompletionSource <object> drawingTcs = new TaskCompletionSource <object>();

                    Console.WriteLine($"Refreshing ground tile at ({tileInfo.X}, {tileInfo.Y}) for zoom level {tileInfo.Zoom} ({zoomScale}) with GPS bounds {tileSpan}");

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        GroundOverlay overlay;

                        lock (_GroundOverlays)
                        {
                            overlay = _GroundOverlays.FirstOrDefault(o => (o.Tag as TileInfo)?.Equals(tileInfo) ?? false);
                        }

                        if (overlay == null)
                        {
                            GroundOverlayOptions overlayOptions = new GroundOverlayOptions().PositionFromBounds(tileSpan.ToLatLng())
                                                                  .InvokeImage(bitmapDescriptor);

                            overlay     = _NativeMap.AddGroundOverlay(overlayOptions);
                            overlay.Tag = tileInfo;

                            lock (_GroundOverlays)
                            {
                                _GroundOverlays.Add(overlay);
                            }
                        }
                        else if ((overlay.Tag as TileInfo)?.NeedsRedraw ?? false)
                        {
                            overlay.SetImage(bitmapDescriptor);
                        }

                        drawingTcs.TrySetResult(null);
                    });

                    await drawingTcs.Task.ConfigureAwait(false);

                    ReleaseOverlayBitmap(bitmap);
                }
                else
                {
                    Console.WriteLine($"Ground tile at ({tileInfo.X}, {tileInfo.Y}) for zoom level {tileInfo.Zoom} already exists");
                }
            }
        }