comparison mupdf-source/thirdparty/zxing-cpp/wrappers/dotnet/ZXingCpp.DemoWriter/Program.cs @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * Copyright 2024 Axel Waggershauser
3 */
4 // SPDX-License-Identifier: Apache-2.0
5
6 using System.Collections.Generic;
7 using SkiaSharp;
8 using ZXingCpp;
9
10 public static class SkBitmapBarcodeWriter
11 {
12 public static SKBitmap Write(Barcode barcode, WriterOptions? opts = null)
13 {
14 var img = barcode.ToImage(opts);
15 var info = new SKImageInfo(img.Width, img.Height, SKColorType.Gray8);
16 var res = new SKBitmap();
17 res.InstallPixels(info, img.Data, img.Width, (IntPtr _, object _) => img.Dispose());
18 return res;
19 }
20
21 public static SKBitmap ToSKBitmap(this Barcode barcode, WriterOptions? opts = null) => Write(barcode, opts);
22 }
23
24 public class Program
25 {
26 public static void Main(string[] args)
27 {
28 var (format, text, fn) = (args[0], args[1], args[2]);
29
30 var bc = new Barcode(text, Barcode.FormatFromString(format));
31
32 var img = bc.ToImage();
33 Console.WriteLine($"{img.Data}, {img.Width}, {img.Height}, {img.ToArray()}");
34
35 if (fn.EndsWith(".svg"))
36 File.WriteAllText(fn, bc.ToSVG());
37 else
38 using (SKBitmap skb = bc.ToSKBitmap(new WriterOptions(){Scale = 5})) {
39 skb.Encode(new SKFileWStream(args[2]), SKEncodedImageFormat.Png, 100);
40 }
41 }
42
43 }