最近、エラーなしで正しく動作するようにアプリケーションを管理しています。バーコードを生成する - アプリケーションはエラーフリーですが、バーコードは生成されません
問題は、テキストが下にあるバーコードを生成することになっていることです。バーコードなしの画像のみを生成します。
私はIDAutomationHC39Mというフォントを使用しています。アプリはテキストをバーコードに変換する必要があります。
以下のコードを参照してください。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String barcode = pole.Text;
Bitmap bitmap = new Bitmap(barcode.Length * 40, 150);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
Font ofont = new System.Drawing.Font("IDAutomationHC39M", 20);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush White = new SolidBrush(Color.White);
graphics.FillRectangle(White, 0, 0, bitmap.Width, bitmap.Height);
graphics.DrawString("*" + barcode + "*", ofont, black, point);
}
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, ImageFormat.Png);
box.Image = bitmap;
box.Height = bitmap.Height;
box.Width = bitmap.Width;
}
}
private void pole_TextChanged(object sender, EventArgs e)
{
}
}
}
あなたはArialのような別のフォント、代わりのバーコードフォントを使用するとどうなりますか – TaW
同じ空白の画像に – Truex
のテキストが入っていますか?ボックスは画像ボックスですか?あなたのコードはここでうまくいく:白い背景のテキスト。 – TaW