From 4f2f01289ea683c8df12dec4092db94b40c45268 Mon Sep 17 00:00:00 2001 From: Lasse Gaardsholt Date: Fri, 12 Mar 2021 23:23:34 +0100 Subject: [PATCH] this works.. (#23) --- barcoder/Controllers/HexController.cs | 14 ++++++++++---- barcoder/Views/Home/Index.cshtml | 6 +++++- barcoder/wwwroot/js/index.js | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/barcoder/Controllers/HexController.cs b/barcoder/Controllers/HexController.cs index 79b6ca3..4159011 100644 --- a/barcoder/Controllers/HexController.cs +++ b/barcoder/Controllers/HexController.cs @@ -10,15 +10,21 @@ public class HexController : ControllerBase { [HttpGet("")] - public IActionResult Get(string color, int width = 300, int height = 300) + public IActionResult Get(string color, string border, int width = 300, int height = 300) { try { + var backgroundColor = ColorTranslator.FromHtml($"#{color}"); + var borderColor = ColorTranslator.FromHtml($"#{border}"); + var image = new Bitmap(width, height); var graph = Graphics.FromImage(image); - var translatedColor = ColorTranslator.FromHtml($"#{color}"); - - graph.Clear(translatedColor); + + using (Graphics g = Graphics.FromImage(image)) + { + g.Clear(backgroundColor); + g.DrawRectangle(new Pen(borderColor, 3), new Rectangle(1, 1, image.Width - 3, image.Height - 3)); + } return File((byte[])(new ImageConverter()).ConvertTo(image, typeof(byte[])), "image/png"); } diff --git a/barcoder/Views/Home/Index.cshtml b/barcoder/Views/Home/Index.cshtml index 3a69776..5d8b0b8 100644 --- a/barcoder/Views/Home/Index.cshtml +++ b/barcoder/Views/Home/Index.cshtml @@ -13,9 +13,13 @@
- +
+
diff --git a/barcoder/wwwroot/js/index.js b/barcoder/wwwroot/js/index.js index 452c0f6..0322ef3 100644 --- a/barcoder/wwwroot/js/index.js +++ b/barcoder/wwwroot/js/index.js @@ -28,24 +28,41 @@ document.querySelectorAll('#barcodeForm input').forEach(item => { function onInputChange(event) { + checkIfHex(); updateBarcodeData(); updateImage(); } +function checkIfHex() { + if (document.getElementById("barcodeType").selectedOptions[0].value == "99999") { + document.getElementById("group-barcodeBorder").style.display = "block"; + document.getElementById("barcodeText-label").innerText = "Box color"; + document.getElementById("barcodeText").type = "color"; + + } else { + document.getElementById("group-barcodeBorder").style.display = "none"; + document.getElementById("barcodeText-label").innerText = "Text"; + document.getElementById("barcodeText").type = "text"; + } +} + function updateBarcodeData() { let barcodeType = parseInt(document.getElementById("barcodeType").selectedOptions[0].value); let barcodeText = document.getElementById("barcodeText").value; let barcodeWidth = parseInt(document.getElementById("barcodeWidth").value); let barcodeHeight = parseInt(document.getElementById("barcodeHeight").value); let barcodeRotate = parseInt(document.getElementById("barcodeRotate").value); + let borderColor = document.getElementById("barcodeBorder").value; + if (barcodeType == "99999") { barcode = { url: "hex.png?", data: { - color: barcodeText, + color: barcodeText.replace("#", ""), width: barcodeWidth, height: barcodeHeight, + border: borderColor.replace("#", "") } }; } else {