Last post Apr 03, 2008 11:11 AM by robg_advernets
Jan 07, 2008 02:26 PM|dzulawski|LINK
I'm having an issue with my image generation code: It generates a barcode (using a barcode font) and is suppose to save the jpg to the web page screen, only when it saves, it overwrites the entire page.
I have the code:
Bitmap oBmp1 = new Bitmap(470, 100);
Graphics oGrp1 = Graphics.FromImage(oBmp1);
Graphics oGrp2 = Graphics.FromImage(oBmp1);
string sText = "*ENG071121010101S*";
string sText2 = "ENG071121010101S";
SolidBrush oBrush = new SolidBrush(Color.White);
SolidBrush oBrushWrite = new SolidBrush(Color.Black);
oGrp1.FillRectangle(oBrush, 0, 0, 470, 100);
PrivateFontCollection pfc = new PrivateFontCollection();
FontFamily family = new FontFamily("Free 3 of 9", pfc);
Font oFont = new Font(family, 45);
Font oFont2 = new Font("Arial", 16);
PointF oPoint = new PointF(5F, 5F);
PointF oPoint2 = new PointF(135, 60);
oGrp1.DrawString(sText, oFont, oBrushWrite, oPoint);
oGrp2.DrawString(sText2, oFont2, oBrushWrite, oPoint2);
Response.ContentType = "image/jpeg";
Any ideas on why it would do this? Any help would be appreciated!
Jan 07, 2008 02:57 PM|rmaiya|LINK
There are two ways you can do this, either create another page called barCodeGen.aspx or write a HTTP handler BarCodegen.ashx and paste your code there, and call that page like
<image src=" barCodeGen.aspx" id=id1 >
Jan 07, 2008 02:59 PM|datagrid|LINK
Well, the issue with the content type. Response.ContentType = "image/jpeg";
A web page can only have one content type. in your case, you could use the following logic:
use a Image web control to display the display. using the code that you posted, you could generate the barcode and save it in the server or other http location. then pass the location URL to the Image web control.
By this way, you will see the image as well as other HTML controls in your web page.
Hope this helps.
Apr 03, 2008 11:11 AM|robg_advernets|LINK
The above is correct. I tried your code and then accessed it with <img src=barcode.aspx?text=MYCODE1234> The only difference is I have Response.ContentType = "image/jpg" in mine and some additional resize of the image canvas background. I have some simililar
code that make the rectangle ratio correct based on the font size requested. I will post in code project. I agree the components out there are over priced. This is a very simple solutions. I'm using in ASP.NET and scanning with Intermec scanners and works
like a charm. Also for people using 3 of 9 font, you will hve to make the font at least 48 or bigger for the scanner to easily pick it up.