Click here to Skip to main content
15,125,104 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi , im trying to creeate a barcode generator , heres my code:
C#
using (MemoryStream ms = new MemoryStream())
            {
                barcode.Save(ms, ImageFormat.Png);
                pictureBox1.Image = bitmap;
                pictureBox1.Height = bitmap.Height;
                pictureBox1.Width = bitmap.Width;

heres my error
'string' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
what refremce should i use for this? all my current refrences>
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
Posted
Comments
DamithSL 4-Aug-15 4:01am
   
what is barcode?
jamesmc1535 4-Aug-15 4:06am
   
like on products at a store, those stripy stuff\
Afzaal Ahmad Zeeshan 4-Aug-15 4:05am
   
barcode in your code is of type string. That is the main cause of problem, not the using block. Where (or how) is it defined?
jamesmc1535 4-Aug-15 4:08am
   
theres my full code
string barcode = textBox1.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())
{
barcode.Save(ms, ImageFormat.Png);
pictureBox1.Image = bitmap;
pictureBox1.Height = bitmap.Height;
pictureBox1.Width = bitmap.Width;

change
C#
barcode.Save(ms, ImageFormat.Png);

to
C#
bitmap.Save(ms, ImageFormat.Png);
   
Comments
jamesmc1535 4-Aug-15 4:12am
   
thanks man lol
Afzaal Ahmad Zeeshan 4-Aug-15 4:17am
   
5ed.
jamesmc1535 4-Aug-15 4:20am
   
i have a quiestion , on all my stuff that u replied u said 5ed. im curious
whats that mean?
Afzaal Ahmad Zeeshan 4-Aug-15 4:24am
   
That means I voted a 5 star on this post. His answer was helpful, so I voted 5 star, short as "5ed".
jamesmc1535 4-Aug-15 4:43am
   
i have another follow up question on this forms ect ect ect, theres a menu where u can edit n forms framework< rightclick properties if i recall perfectly but its not working
Afzaal Ahmad Zeeshan 4-Aug-15 4:44am
   
You may start a new thread for another question James.
jamesmc1535 4-Aug-15 4:43am
   
thanks
DamithSL 4-Aug-15 4:27am
   
:) you know that codeproject having Reputation system[^]? Afzaal here rated as 5 and he is mentioned it as comment.
jamesmc1535 4-Aug-15 4:43am
   
ive seen the rating system but didnt know what 5 ed meant lol thanks btw i have another follow up question on this forms ect ect ect, theres a menu where u can edit n forms framework< rightclick properties if i recall perfectly but its not working
barcode is a string - the error message says that - which means that it isn't an image of a barcode, it's a string containing the Article Number: "5013719020011"
If you want to convert it to a MemoryStream so you can save the image bytes in a database for example, then you need to first create a barcode image from that number. The framework doesn't know that you want a Code 39 or an EAN128 barcode just because you have a number in a string! :laugh:

Look at the rest of your code, and see where you have create the image - I'd suspect that you want to use bitmap instead.
   
Comments
jamesmc1535 4-Aug-15 4:13am
   
yup bitmaps the right one so its workin now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900