Advertisement

04.03.2008 at 04:07PM PDT, ID: 23294551
[x]
Attachment Details

C# Drawing text on image keeps coming out too blurry

Asked by twcadmin in C# Programming Language, Miscellaneous Web Development, .NET

Tags: c# .net

I'm trying to draw a barcode image. I have the barcode font installed on my server and using the code below i can draw text to my screen using the font BUT it comes out too blurry so when i go to print it, the barcode is unuseable. If i type the same barcode using microsoft word and print it out it comes out perfectly clear so i know theres nothing wrong with the font or the printer. I changed the font to Arial so everyone else can see the code for themselves and test it out if they want.

I'm lost as to how i'm suppose to make this image more clear.

Excuse the sloppy code but i'm learning and experimenting a lot.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
<%@ Page Language="C#" %>
<%@Import Namespace="System" %>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Reflection" %>
<%@Import Namespace="System.Drawing" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<%@Import Namespace="System.Drawing.Drawing2D" %>
<%@Import Namespace="System.Drawing.Text" %>
<%Response.ContentType="image/jpg";%>
 
 
<script runat="server">
 
 
void Page_Load(object sender, EventArgs e)
{
Bitmap myBitmap = new Bitmap(10,100);
//"C:\\inetpub\\wwwroot\\winxp2.jpg"
 
//Graphics grf = Graphics.FromImage(myBitmap);
/*
    System.Drawing.Graphics formGraphics = Graphics.FromImage(myBitmap);
    formGraphics.Clear(Color.White);
    string drawString = "Sample Text";
    System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
    System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
    float x = 0.0f;
    float y = 0.0f;
    formGraphics.DrawString(drawString, drawFont, drawBrush, x, y);
    //myBitmap.Save("C:\\inetpub\\wwwroot\\winxp23.jpg");
    myBitmap.Save(Response.OutputStream, ImageFormat.Gif);
    drawFont.Dispose();
    drawBrush.Dispose();
    formGraphics.Dispose();
  */  
    //Image i = Image.FromFile(filename);
 
// Set Content Type to GIF
 Response.ContentType = "image/gif";
 
 String theText = "123456789";
 
 // Create Image
  Bitmap objBitmapTMP = new Bitmap(1,1);
 Graphics g = Graphics.FromImage(objBitmapTMP);//CreateGraphics();
 
  Font fontDesc = new Font("IDAutomationHC39M-Scaled",10);
  
  
 SizeF stringSize = g.MeasureString(theText,fontDesc);
 
 int width =(int) stringSize.Width;
 int height = (int) stringSize.Height;
 Bitmap objBitmap = new Bitmap(width, height);
 Graphics objGraphics = Graphics.FromImage(objBitmap);
 objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);
 
 // Create Font and String Format
 
 StringFormat stringFormat = new StringFormat();
 stringFormat.Alignment = StringAlignment.Near;
 stringFormat.LineAlignment = StringAlignment.Center;
 
//SizeF stringSize = new SizeF();
//stringSize = e.Graphics.MeasureString(theText, fontDesc);
 
 
 // Draw the String
 objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
 objGraphics.TextContrast = 0;
 objGraphics.InterpolationMode=InterpolationMode.HighQualityBicubic;
 //objGraphics.SetResolution(600f, 600f);
 objBitmap.SetResolution(1200f, 1200f);
 objGraphics.DrawString(theText, fontDesc, new SolidBrush(Color.Black), new Rectangle(0, 0, width, height), stringFormat);
 
 // Save the Image to the OutputStream
 objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
 
 // Clean Up
 objGraphics.Dispose();
 
 
}
 
 
</script>
[+][-]04.03.2008 at 04:19PM PDT, ID: 21277844

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 06:43PM PDT, ID: 21278501

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 07:15PM PDT, ID: 21278593

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 08:58PM PDT, ID: 21278973

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.03.2008 at 09:00PM PDT, ID: 21278988

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 07:07AM PDT, ID: 21281826

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 07:41AM PDT, ID: 21282220

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.04.2008 at 09:44AM PDT, ID: 21283471

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.09.2008 at 07:02PM PDT, ID: 21969868

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 10:09PM PDT, ID: 21970561

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, Miscellaneous Web Development, .NET
Tags: c# .net
Sign Up Now!
Solution Provided By: CyrexCore2k
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628