Last active
December 20, 2015 23:39
-
-
Save davidalencar/6214310 to your computer and use it in GitHub Desktop.
Create DANFE bar code image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client static Bitmap barCode(str _data) | |
{ | |
System.Drawing.Bitmap barCode; | |
System.Drawing.Font font; | |
System.Drawing.Graphics graphics; | |
System.Drawing.SizeF dataSize; | |
System.String data; | |
System.Drawing.Brush brush; | |
System.IO.MemoryStream stream; | |
Image barCodeImage; | |
Int64 barcodeBitmapPtr; | |
BinData binData; | |
; | |
new InteropPermission(InteropKind::ClrInterop).assert(); | |
data = _data; | |
barCode = new System.Drawing.Bitmap(1, 1); | |
font = new System.Drawing.Font("BC C128 Narrow", 38, System.Drawing.FontStyle::Regular); | |
graphics = System.Drawing.Graphics::FromImage(barCode); | |
dataSize = graphics.MeasureString(data, font); | |
barCode = new System.Drawing.Bitmap(barCode, dataSize.ToSize()); | |
graphics = System.Drawing.Graphics::FromImage(barCode); | |
graphics.Clear(System.Drawing.Color::get_White()); | |
graphics.set_TextRenderingHint(System.Drawing.Text.TextRenderingHint::ClearTypeGridFit); | |
brush = System.Drawing.Brushes::get_Black(); | |
graphics.DrawString(data, font, brush, 0, 0); | |
graphics.Flush(); | |
BarcodeImage = new Image(); | |
barcodeBitmapPtr = barcode.GetHbitmap(); | |
BarcodeImage.importBitmap(barcodeBitmapPtr); | |
CodeAccessPermission::revertAssert(); | |
return BarcodeImage.getData(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment