本文整理汇总了C#中ZXing.BarcodeWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BarcodeWriter.Write方法的具体用法?C# BarcodeWriter.Write怎么用?C# BarcodeWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZXing.BarcodeWriter
的用法示例。
在下文中一共展示了BarcodeWriter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCode
static void DrawCode(string code, ImageView barcode)
{
var writer = new BarcodeWriter
{
Format = BarcodeFormat.CODE_39,
Options = new EncodingOptions
{
Height = 200,
Width = 600
}
};
var bitmap = writer.Write(code);
Drawable img = new BitmapDrawable(bitmap);
barcode.SetImageDrawable(img);
}
示例2: ToImage
/// <summary>
///
/// </summary>
/// <param name="code"></param>
/// <param name="size"></param>
/// <returns></returns>
public static Bitmap ToImage(string code, int size = 180)
{
BarcodeWriter writer = new BarcodeWriter();
QrCodeEncodingOptions qr = new QrCodeEncodingOptions()
{
CharacterSet = "UTF-8",
ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
Height = size,
Width = size,
};
writer.Options = qr;
writer.Format = BarcodeFormat.QR_CODE;
Bitmap bitmap = writer.Write(code);
return bitmap;
}
示例3: decodeBarcodeText
private static string decodeBarcodeText(System.Drawing.Bitmap barcodeBitmap)
{
var source = new BitmapLuminanceSource(barcodeBitmap);
// using http://zxingnet.codeplex.com/
// PM> Install-Package ZXing.Net
var reader = new BarcodeReader(null, null, ls => new GlobalHistogramBinarizer(ls))
{
AutoRotate = true,
TryInverted = true,
Options = new DecodingOptions
{
TryHarder = true,
//PureBarcode = true,
/*PossibleFormats = new List<BarcodeFormat>
{
BarcodeFormat.CODE_128
//BarcodeFormat.EAN_8,
//BarcodeFormat.CODE_39,
//BarcodeFormat.UPC_A
}*/
}
};
//var newhint = new KeyValuePair<DecodeHintType, object>(DecodeHintType.ALLOWED_EAN_EXTENSIONS, new Object());
//reader.Options.Hints.Add(newhint);
var result = reader.Decode(source);
if (result == null)
{
Console.WriteLine("Decode failed.");
return string.Empty;
}
Console.WriteLine("BarcodeFormat: {0}", result.BarcodeFormat);
Console.WriteLine("Result: {0}", result.Text);
var writer = new BarcodeWriter
{
Format = result.BarcodeFormat,
Options = { Width = 200, Height = 50, Margin = 4},
Renderer = new ZXing.Rendering.BitmapRenderer()
};
var barcodeImage = writer.Write(result.Text);
Cv2.ImShow("BarcodeWriter", barcodeImage.ToMat());
return result.Text;
}
示例4: OnNavigatedTo
protected override void OnNavigatedTo(NavigationEventArgs e)
{
IBarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 300,
Width = 300,
},
Renderer = new ZXing.Rendering.PixelDataRenderer() { Foreground = Colors.Black }
};
var result = writer.Write("www.microsoft.com");
var wb = result.ToBitmap() as WriteableBitmap;
QrcodeImg.Source = wb;
}
示例5: MainWindowPresenter
public MainWindowPresenter()
{
// init server connection
InitializePresItServiceClient();
// create random session ID to be authenticated by user
var sessionId = Guid.NewGuid().ToString();
// create and show QR code of session ID
var writer = new BarcodeWriter {
Format = BarcodeFormat.QR_CODE,
Options = new QrCodeEncodingOptions {Margin = 1}
};
var result = writer.Write(sessionId);
var img = new BitmapImage();
using (var memory = new MemoryStream()) {
result.Save(memory, ImageFormat.Png);
memory.Position = 0;
img.BeginInit();
img.StreamSource = memory;
img.CacheOption = BitmapCacheOption.OnLoad;
img.EndInit();
}
barcodeImage = img;
// Connect to server and wait until we get authenticated
new Thread(() => {
while (true) {
try {
clientId = service.IsAuthenticated(sessionId);
if (clientId == null) continue;
if (IsAuthenticated != null) IsAuthenticated(this, EventArgs.Empty);
break;
} catch (TimeoutException) {
}
}
}).Start();
// create slide importers
importers = new List<ISlidesImporter> {
new ImageImporter(),
new PowerPointImporter()
};
}
示例6: GenerateMatrixCode
public static IHtmlString GenerateMatrixCode(this HtmlHelper html, string inputentry, int height = 250, int width = 250, int margin = 0)
{
var qrValue = inputentry + " "; // 10 trailing spaces added to guard against unpredictabilty.
var barcodeWriter = new BarcodeWriter
{
Format = BarcodeFormat.DATA_MATRIX,
Options = new EncodingOptions
{
Height = height,
Width = width,
Margin = margin
}
};
using (var bitmap = barcodeWriter.Write(qrValue))
using (var stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Gif);
var img = new TagBuilder("img");
img.MergeAttribute("alt", "matrix barcode");
img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}",
Convert.ToBase64String(stream.ToArray())));
return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
}
}
示例7: GenerateLinearCode
public static IHtmlString GenerateLinearCode(this HtmlHelper html, string inputentry, int height = 210, int width = 900, int margin = 0)
{
var qrValue = inputentry;
var barcodeWriter = new BarcodeWriter
{
Format = BarcodeFormat.CODE_39,
Options = new EncodingOptions
{
Height = height,
Width = width,
Margin = margin,
PureBarcode = true
}
};
using (var bitmap = barcodeWriter.Write(qrValue))
using (var stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Gif);
var img = new TagBuilder("img");
img.MergeAttribute("alt", "code39 barcode");
img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}",
Convert.ToBase64String(stream.ToArray())));
return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
}
}
示例8: GeneratorQrCodeImage
/// <summary>
/// 生成二维码图片
/// </summary>
/// <param name="contents">要生成二维码包含的信息</param>
/// <param name="width">生成的二维码宽度(默认300像素)</param>
/// <param name="height">生成的二维码高度(默认300像素)</param>
/// <returns>二维码图片</returns>
public static Bitmap GeneratorQrCodeImage(string contents, int width = 300, int height = 300)
{
if (string.IsNullOrEmpty(contents))
{
return null;
}
EncodingOptions options = null;
BarcodeWriter writer = null;
options = new QrCodeEncodingOptions
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = width,
Height = height,
ErrorCorrection = ErrorCorrectionLevel.H,
//控制二维码图片的边框
Margin = 0
};
writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = options
};
Bitmap bitmap = writer.Write(contents);
return bitmap;
}
示例9: ProcessLabelItem
private static void ProcessLabelItem(LabelItem labelItem, Graphics g, PrintLabelSettings settings)
{
switch (labelItem.LabelType)
{
case LabelTypesEnum.Label:
g.DrawString(labelItem.LabelText,
new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
Brushes.Black, labelItem.StartX, labelItem.StartY);
break;
case LabelTypesEnum.BarCode:
var content = labelItem.LabelText;
var writer = new BarcodeWriter
{
Format = BarcodeFormat.CODE_128,
Options = new ZXing.QrCode.QrCodeEncodingOptions
{
ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
Width = settings.BarCodeMaxWidth,
Height = settings.BarCodeHeight,
PureBarcode = true,
}
};
var barCodeBmp = writer.Write(content);
g.DrawImageUnscaled(barCodeBmp, labelItem.StartX, labelItem.StartY);
break;
case LabelTypesEnum.Stamp:
var pen = new Pen(Color.Black, 2);
g.DrawEllipse(pen, labelItem.StartX, labelItem.StartY, settings.StampDiameter, settings.StampDiameter);
g.DrawString(labelItem.LabelText,
new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
Brushes.Black, labelItem.StartX + 2, labelItem.StartY + 11);
break;
}
}
示例10: GetCode128
public HttpResponseMessage GetCode128(string value, int? height = null)
{
if (value == null || value.Length == 1 || value.Length > 80) {
var errorResponse = new HttpResponseMessage(HttpStatusCode.BadRequest) {
Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new { Error = "Value must be between 1 and 80 characters." })),
};
return errorResponse;
}
var response = new HttpResponseMessage();
var writer = new BarcodeWriter() {
Format = BarcodeFormat.CODE_128,
};
if (height.HasValue) {
writer.Options.Hints[ZXing.EncodeHintType.HEIGHT] = height.Value;
}
Bitmap barcodeBitmap = writer.Write(value);
using (var pngStream = new MemoryStream()) {
barcodeBitmap.Save(pngStream, ImageFormat.Png);
response.Content = new ByteArrayContent(pngStream.ToArray());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
return response;
}
}
示例11: GetCell
public override UITableViewCell GetCell (UITableView tv)
{
var cell = tv.DequeueReusableCell(this.CellKey);
UIImageView iv = null;
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, this.CellKey);
iv = new UIImageView(new RectangleF(10f, 5f, tv.Bounds.Width - 20f, this.MaxHeight - 10f));
iv.Tag = 101;
iv.ContentMode = UIViewContentMode.ScaleAspectFit;
cell.AddSubview(iv);
}
else
{
iv = cell.ViewWithTag(101) as UIImageView;
}
if (this.barcodeImg == null)
{
var writer = new BarcodeWriter() { Format = this.format };
this.barcodeImg = writer.Write(this.value);
}
iv.Image = this.barcodeImg;
return cell;
}
示例12: GenerateRelayQrCode
public static IHtmlString GenerateRelayQrCode(this HtmlHelper html, string alt, string value, int height = 250, int width = 250, int margin = 0)
{
var barcodeWriter = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new EncodingOptions
{
Height = height,
Width = width,
Margin = margin
}
};
using (var bitmap = barcodeWriter.Write(value))
using (var stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Gif);
var img = new TagBuilder("img");
img.MergeAttribute("alt", alt);
img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}",
Convert.ToBase64String(stream.ToArray())));
return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
}
}
示例13: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
lblResult.Text = "";
txInput.Text = "http://thinkpower.info/xamarin/cn/";
//扫描条码
btnScan.TouchUpInside += async (sender, e) => {
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
if (result != null)
this.lblResult.Text = result.Text;
};
//产生条码
btnGenerateBarCode.TouchUpInside += (sender, e) => {
txInput.ResignFirstResponder();
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE
};
var bitmap = writer.Write(txInput.Text);
this.img_code.Image = bitmap;
};
}
示例14: Update
private async void Update()
{
var writer1 = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new ZXing.Common.EncodingOptions
{
Height = 200,
Width = 200
},
};
var image = writer1.Write(Text);//Write(text);
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
{
using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
{
writer.WriteBytes(image);
await writer.StoreAsync();
}
var output = new BitmapImage();
await output.SetSourceAsync(ms);
ImageSource = output;
}
}
示例15: Main
static void Main(string[] args)
{
var parsedArgs = new Arguments();
if (args.Length == 0)
{
Console.WriteLine(Parser.ArgumentsUsage(typeof(Arguments)));
return;
}
if (!Parser.ParseArgumentsWithUsage(args, parsedArgs))
{
Console.WriteLine("Can't parse arguments");
return;
}
var writer = new BarcodeWriter
{
Format = BarcodeFormat.QR_CODE,
Options = new EncodingOptions
{
Height = parsedArgs.Size,
Width = parsedArgs.Size,
PureBarcode = true,
Margin = 0
},
Renderer = (IBarcodeRenderer<Bitmap>) Activator.CreateInstance(typeof (BitmapRenderer))
};
var bitmap = writer.Write(parsedArgs.Content);
bitmap.SetResolution(parsedArgs.DPI, parsedArgs.DPI);
bitmap.Save(parsedArgs.Output);
}