// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace Spludlow.Drawing { public class DrawShapes { public static void Cross(Spludlow.Printing.IPrintDoc doc, float x, float y) { Cross(doc, x, y, Color.Red, 2, 0.5F); } public static void Cross(Spludlow.Printing.IPrintDoc doc, float x, float y, Color colour) { Cross(doc, x, y, colour, 2, 0.5F); } public static void Cross(Spludlow.Printing.IPrintDoc doc, float x, float y, Color colour, float size, float stroke) { size /= 2; doc.Line(x - size, y, x + size, y, stroke, colour); doc.Line(x, y - size, x, y + size, stroke, colour); } public static void BitmapToVector(Spludlow.Printing.IPrintDoc printDoc, string bitmapFilename, float x, float y, float pixelSize, float gridWeight) { BitmapToVector(printDoc, bitmapFilename, x, y, pixelSize, pixelSize, gridWeight); } public static void BitmapToVector(Spludlow.Printing.IPrintDoc printDoc, string bitmapFilename, float x, float y, float xPixelSize, float yPixelSize, float gridWeight) { using (Image image = Image.FromFile(bitmapFilename)) { using (Bitmap bitmap = new Bitmap(image)) { for (int pass = 0; pass < 2; ++pass) { if (pass == 1 && gridWeight == 0) break; for (int yPos = 0; yPos < image.Height; ++yPos) { float y1 = yPixelSize + yPos * yPixelSize; for (int xPos = 0; xPos < image.Width; ++xPos) { float x1 = xPixelSize + xPos * xPixelSize; Color color = bitmap.GetPixel(xPos, yPos); if (color.A != 0) { if (pass == 0) printDoc.Rectangle(x + x1, y + y1, xPixelSize, yPixelSize, 0, Color.Empty, color); else printDoc.Rectangle(x + x1, y + y1, xPixelSize, yPixelSize, gridWeight, Color.Black, Color.Empty); } } } } } } } public static Color[][] BitmapToArray(string bitmapFilename) { using (Image image = Image.FromFile(bitmapFilename)) { using (Bitmap bitmap = new Bitmap(image)) { Color[][] result = new Color[bitmap.Width][]; for (int x = 0; x < bitmap.Width; ++x) { result[x] = new Color[bitmap.Height]; for (int y = 0; y < bitmap.Height; ++y) { Color color = bitmap.GetPixel(x, y); if (color.A != 0) { result[x][y] = color; } else { result[x][y] = Color.Empty; } } } return result; } } } } }