跳到主文
部落格全站分類:心情日記
最近在思索一些有關條碼的程式設計
目前想到的方法是利用網路上四處可見的條碼字型來實現
但不知是怎一回事,似乎只要字型一小於 50 ,他條碼就會連在一起,我也不知這樣的條碼是不是能正常讀取
後面應該會看看能不能用單純繪圖的方式來產生條碼
這樣不用字型也能運作,而且要畫什麼都在自己的掌控之內
protected void Page_Load(object sender, EventArgs e) { string s = Request.QueryString["Code"]; if (s == null || string.IsNullOrEmpty(s)) s = "*12345*"; Response.Clear(); global::System.Drawing.Bitmap Img = new global::System.Drawing.Bitmap(1,1); global::System.Drawing.Graphics g = global::System.Drawing.Graphics.FromImage(Img); global::System.Drawing.Font f = new System.Drawing.Font("3 of 9 Barcode", 50.0f); global::System.Drawing.Font f2 = new System.Drawing.Font("新細明體", 20.0f); global::System.IO.MemoryStream m; global::System.Drawing.SizeF sf = g.MeasureString(s, f); global::System.Drawing.SizeF sf2 = g.MeasureString(s, f2); int _w = s.Length * System.Convert.ToInt32(sf.Width); int _h = System.Convert.ToInt32(sf.Height); Img = new global::System.Drawing.Bitmap(global::System.Convert.ToInt32(sf.Width + 0.5), global::System.Convert.ToInt32(sf.Height + sf2.Height + 0.5)); g = global::System.Drawing.Graphics.FromImage(Img); sf = g.MeasureString(s, f); g.DrawString(s, f, new global::System.Drawing.SolidBrush(global::System.Drawing.Color.Black), new global::System.Drawing.PointF(0, 0)); g.DrawString(s, f2, new global::System.Drawing.SolidBrush(global::System.Drawing.Color.Black), new global::System.Drawing.PointF((sf.Width - sf2.Width) / 2, sf.Height)); m = new global::System.IO.MemoryStream(); Img.Save(m, global::System.Drawing.Imaging.ImageFormat.Png); Img.Dispose(); Img = null; Response.ContentType = "image/Png"; Response.BinaryWrite(m.ToArray()); Response.End(); }
上面就是我的實驗作
天翼翔幻
MyWCT 發表在 痞客邦 留言(0) 人氣()
留言列表