 |
|
 |
Found that bug ... fix will be released in version 1.0.0.10 ... Pomp did find the right place for the fix by the way.
Thanks to both of you, another bug is fixed.
Brad Barnhill
|
|
|
|
 |
|
 |
| Laptop power plug died so Im without the machine I work on this library for 4-5 business days. So yet another delay in getting this out. Brad Barnhill
|
|
|
|
 |
 | Barcode width compress awadhesh4772 | 22:25 18 Jan '10 |
|
 |
Hi Brad,
I am very glad to use your barcode library.. it is really very helpfull.
I just wanted to know how can compress barcode width. E.g. I wanted to print 12 digit no on 4.0cm wider label with code 128B, which is going out now.
Thanks for your reply. Awadhesh
|
|
|
|
 |
|
 |
You dont have the option of setting width via (cm or inches) but you do have the option to adjust it via pixel width. If you find a pixel width that works stick with that width and it should work just fine.
Let me know if that helps.
Brad Barnhill
|
|
|
|
 |
|
 |
Thanks for your reply. I already used 170 x 30 pixel to determine barcode dimesion for 12 digit numbers. pls refere below script line.
e.Graphics.DrawImage(BarcodeLib.Barcode.DoEncode(barType(cbSymbology.SelectedItem), "A000000012 1", False, 170, 30)
but I want to print barcode in compressed mode instead of normal mode.
If i m reduce pixel less than 170, I got error "Image size specified not large enough to draw barcode".
Hope you understand my requirement. seek your help.
regards, awadhesh
|
|
|
|
 |
|
 |
It's not possible to reduce the bitmap width further. The barcode you want to draw encodes to a certain number of bars and spaces. If you specify a bar-width of 1 pixel (the smallest value you can use) and if your barcode comes to 170 bars, you won't be able to fit it in a bitmap that is smaller than 170 pixels. The only way you can use a smaller bitmap is therefore to use fewer bars, which means encoding less data - which is not much use to you.
Since you want to print a barcode that is in real-world measurements (4cm, you say) you can set the DPI of the bitmap before creating a Graphics object for it. This sets the number of pixels-per-inch for your barcode. It will still be 170 pixels, but will print 4cm.
If you require a 4cm barcode, you convert 4cm to inches and divide your bitmap width (in pixels) by the result. This tells you how many pixels you will need to squeeze into 1 inch. So you can then set the DPI of your bitmap accordingly.
For example, in C#:
<pre>// 1cm = 0.393700787 inches float cm = 4f; float pixelwidth = 170f; float dpi = (float)( (decimal)( pixelwidth / ( cm * 0.393700787f ) );
Bitmap canvas = new Bitmap( pixelwidth, 30 ); canvas.SetResolution( dpi, dpi );
using ( Graphics surface = Graphics.FromImage( canvas ) ) { surface.DrawImage(BarcodeLib.Barcode.DoEncode(barType(cbSymbology.SelectedItem), "A000000012 1", False, pixelwidth, 30), etc... // etc. }</pre>
(I don't know if that code will compile directly; I just typed it in this reply box, but it should give you a fair idea)
|
|
|
|
 |
 | Re: Barcode width compress Brad Barnhill | 15:29 26 Jan '10 |
|
 |
Awad ... fear is correct ... if you have a barcodes data and you feed it to the library it automatically determines what width to draw the bars and still get them into the given size image. If it is smaller than 1px wide for each bar then it throws that error. Its a battle of give and take ... if you want more data encoded you will have to have more space to draw it, even with 1px wide bars. So at 170px wide and that amount of data you will either have to make it wider than 170 or shorten your data somehow. Unless you can draw in smaller than 1px wide lines, which im pretty sure you cant, someone correct me if I am wrong. Awad let me know if this helps explain it, even though it doesnt solve you delimia. Let me know if we need to help you some more or whatever. I aim to please and will help, just ask fear (which is a godsend to this library in answering questions).
Hum this gives me an idea fearmint ... what if i incorporated a resize function into the library with this code? I tried this once before and the barcodes were flaky at best due to the compression of the images and what it does to the bars. They look good when printed just they wont scan ...
Have you tested this much?
Please let me know ... Im interested in re-adding this again if it works.
Thanks,
Brad Barnhill
|
|
|
|
 |
|
 |
Brad, I have same problem too. 4cm and the code must fit in it...
I have tried to convert drawing to bmp, i could change size whatever i want but barcode scaner could not scan it. because when i resize it form orginal size, bitmap was deforming (or bitmap quility maybe poor). If you can solve this, let me know.
thans for this library.
Judasis
|
|
|
|
 |
|
 |
Ok let me explain this one more time:
The smallest you can draw a line in C# is 1 pixel wide. When you specify a size of 300 pixels or whatever then the barcode you want to draw in that space must fit in that space with a minimum bar width of 1 pixel or it will throw an error. This is NOT a bug, it happens when you try to encode an amount of data that it determines can not fit in that space. If you resize the image once its drawn it will cause blurring on the edges. This was how the first version of the library did sizing which was quickly removed due to how many problems it caused.
So in short. When you specify a type of barcode, and a set of data to encode. That data is then used to calculate the maximum bar width that can be used to draw that barcode in that space available. This is then considered the bar width. If that width is less than 1 (pixel) then it will throw an error, because it can not draw a bar less than 1 pixel wide. This is on purpose, this is not a bug. You are trying to fit a barcode in a space that it can NOT be drawn.
Let me know if that makes any sense. Fearmint feel free to chime in here. I believe I explained it but I have been up for 48 hours straight and no end in sight yet ... so ... It may be a little rough around the edges
Thanks,
Brad Barnhill
|
|
|
|
 |
|
 |
I'm getting a bit tired of answering this same question myself!
ok...
judasizm, you say that you want a 4cm wide barcode. However, you are getting a bitmap whose dimensions are pixels, not centimetres. So what is 4cm in pixels? How many pixels fit into a centimetre? The property that determines this is the DPI (dots-per-inch) - see my reply four posts up in this very thread.
The barcode you generate is only larger than 4cm because the default DPI for a bitmap is something like 96. A barcode that has 170 bars/spaces in it (for example), drawn at 1 pixel per bar/space, at 96dpi comes to about 4.498cm (not considering quiet zones or space for bearer bars, etc); clearly larger than 4cm.
You are saying that your generated barcode bitmap doesn't fit in 4cm, but it's a bitmap whose width and height are pixels, not cm. You need to calculate the DPI that enables your pixel width to fit into 4cm (which I explained earlier in this thread, and other threads), then create a bitmap and set its DPI to this value, then draw your barcode on it (either by altering brad's library to draw the bars directly or by drawing the bitmap that the library creates onto another bitmap which has the correct DPI).
(You do need to set DPI *before* creating a Graphics object to do the drawing)
Brad, I think the problem that people have is that barcodes are really only any use when printed and people want to print them at a specific size (in inches, centimetres, millimetres, etc) not pixels - pixels don't mean anything in printing. Your library only allows setting the size of a barcode in pixels. You might fancy creating a simple class or struct of metrics properties that can be passed to the barcode class to provide the real-world-unit widths and heights of the various parts of the barcode. (Maybe also a property specifying what units those sizes are measured in.) Then you can create a bitmap that exactly fits your barcode and have the dpi set to something that will fit those pixels into the required real-world-unit size.
ie: public class CanvasMetrics { AUnitsOfMeasurementEnum Units; float BarcodeWidth; float BarcodeHeight; float LabelHeight; float QuietZoneWidth; float BearerBarTopThickness; float BearerBarBottomThickness; float BearerBarLeftThickness; float BearerBarRightThickness; // etc }
(Of course, if you go down this route you'll eventually get to the problem of how to draw the text label so it fits in the specified inch width, but that's a whole other story )
|
|
|
|
 |
|
 |
Yeah I plan on adding the ability to specify a measurement in real world dimensions (cm, in... etc) I just have to find time to add it.
This is a great idea but I dont know that Ill go to the length of creating quiet zone space, and bearer bar thickness that they can set ... this just opens a WHOLE new can of worms.
Brad Barnhill
|
|
|
|
 |
|
 |
I like the common sense that fearmint is adding here, describing that there is a minimum amount of pixels below which one cannot go to represent a bar code. In general this number occurs when 1 physical pixel is equal to 1 module in a symbology. Think of a module as the fundamental unit in a bar code where the narrowest element is defined as one module wide (so a Code 128 character is 11 modules wide, and a Code 39 character whose wide to narrow ratio is 'N' is 3N+6 modules wide not counting the intercharacter gap, etc.). Printers have a similar fundamental unit - their dot size, where a dot is the smallest mark the printer can make.
The correct way to print a bar code is to have each module be some integer number of printer dots (and greater than 1 for better results). Printers don't print half-dots, otherwise -that- would be their dot size. Trying to print a fractional dot is like rescaling an image from 170 to 150 pixels. At some point information has to get thrown away. In a bar code, discarding that kind of information often leaves the symbol unreadable, no matter how pretty it may look to the eye (oh, to have a nickel for every user who said, "The code looks great, it just doesn't scan...").
Please consider all this when thinking about the strategy posted above about setting a bitmap's DPI. It's not quite enough to simply set a bitmap's resolution to allow it's pixels to fit in a given physical width. If that resolution is greater than what the printer supports, then you still have the same problem of rescaling, just shifted to the printer instead of the screen image.
The usual strategy other print software has taken is not too different that what fearmint is driving toward. The low level symbology functions deal with plain pixels (here it would be Brad's library) and some kind of user interface deals with the physical world (here it would be the modified application, or maybe a wrapper for the library). Usually the user specifies the "X dimension" (the physical width of a module) and determines if the resulting symbol has an acceptable size. Good software limits X dimension selection only to what's possible on a given printer or at a given resolution. So far this is all possible within this implementation.
Quiet zones are a separate topic...
|
|
|
|
 |
|
 |
If I end up implementing the measurement specification of size instead of just pixels then I may consider quiet zone specification ... finding time is just really difficult right now. Ill get to it at some point. Next step is to review the new symbology that just arrived via email and try to make sure it conforms to the library. Then releasing a new version due to a few bugs getting fixed and a new symbology.
Hope you all just 'keep the faith' (Ive slept about 4-5 hours in the last 72)
Time for some rest.
Brad Barnhill
|
|
|
|
 |
|
 |
why don't you try metafile format? i have writen similar barcode library but i used bmp as you. bmp endless way i know. i didn't say "bug". this code is greate, but there is something we may give idea to whom created this code. i don't have enough time now, to spend for this code . but i will. First of all, i'll convert your code bmp to metafile and finaly convert again to bmp. i hope it may solve resizing problem. best regards, Judasis
|
|
|
|
 |
|
 |
what? I just dont understand what you are trying to say. I am the one the created this library. If you have a valid way to resize and it not distort the dimensions of the image then Im all ears.
So Im confused as to what you were trying to say ... just let me know Im all ears.Brad Barnhill
|
|
|
|
 |
|
 |
Resizing a bar code is a bad idea. Using a different file format will not magically allow the reduction of a bar code image that is already created at 1 pixel per module. Instead of trying to scale an image into an area, choose the smallest X dimension that the printer can produce (and your scanner can read) and choose a symbology that can produce a symbol whose width (including quiet zones) fits within the desired space. Then print that image without rescaling. At this point if the code doesn't fit, then it really doesn't fit and something else has to give (higher resolution printer, larger label, multiple symbols using append, higher capacity symbology, ...).
It's also best to print a symbology according to it's specification. Most rules offered in the specs are designed to produce the smallest symbol within the symbology's capabilities. The classic example is Code 128. When users choose to ignore the standard and print with only one subset they often overlook opportunities to take advantage of the code's inherent numeric compression. In the post that started this thread, it said, "I wanted to print 12 digit no on 4.0cm wider label with code 128B". Instead of forcing subset B, let the symbol be produced naturally. That "12 digit no" will use subset C under the hood and the symbol will go from 167 modules to 101 modules wide (not counting quiet zones).
|
|
|
|
 |
|
 |
| Very nicely put ... I cant explain it to people why it cant be resized. I have tried it and tried it and it just doesnt fair well for scanning them after you resize an image and pixel approximation occurs. Its not like I havent tried it. It was the way the library was first designed to work but I had to rewrite a lot of it to allow for dynamic sizing of the bars. When they start resizing the barcodes and 80% scan they will understand I guess. Brad Barnhill
|
|
|
|
 |
|
 |
Here it is in simple terms: RESIZING and BARCODES dont mix. Since I cant draw it smaller than 1 pixel wide bars then if you specify data that is encoded with whatever type of encoding you choose it will not be able to draw it even with 1 pixel wide bars. If you try to resize a bigger image it will not scan. It is not the libraries fault. It could be the amount of data and the symbology you have chosen will not work together and fit in the space you have allocated. This is something that must be taken into account before you randomly chose a symbology. Think about what the symbology encodes and do you really need C128 if you are encoding all numbers? There are more compact codes for numbers.
Just another thought on this topic...Brad Barnhill
|
|
|
|
 |
|
 |
I think Code 128 is actually a great choice for encoding numeric data, being both robust and efficient. What alternatives were you thinking about that are more compact?
|
|
|
|
 |
|
 |
| Code 128 uses 11 units to encode two numbers where as Code11 uses 10. I guess I thought some of the others were more compact but they arent. C128 isnt more compact at all if you exclude char set C. I dont know why you would limit it to one encoding set? Brad Barnhill
|
|
|
|
 |
|
 |
Code 11 encodes a single digit per symbol character.
I don't know why there are users who favor using a subset of Code 128. Users are better served by not messing with this detail.
|
|
|
|
 |
|
 |
I totally agree. It automatically switches between the subsets as needed to better compress the barcode. So I dont know why they mess with it either. Ohh well ... Brad Barnhill
|
|
|
|
 |
|
 |
Hi All,
I am back after long time.. Good discussion with different opion on thread started..
Actully this query was not about scalling unit (pixel or Cm) as some people mentioned.. The requirement is more amount of data draw on less space (e.g. fit 3 people in 2 seater car by squeezing body).
I have seen some other of barcode tool which allow to draw barcode in normal and compact mode.
Anyway, Thanks to everyone for giving openion to manage it... special thanks to Brad to spending time to reply everyone query..Thanks
|
|
|
|
 |
|
 |
you cant just narrow all bars by 1px or anything like that it would change the represented data and more than likely not scan. If you can give me an example of a product that does this maybe I will understand better.
My understanding as of right now you want to compress a barcode further than it already is ... at this moment this library expands the barcode drawing with the widest bars possible to fit the barcode to the space that you specify. If it draws in a space and uses 1px wide bars then that is as small as it can go in that given space.
We will get this hashed out one day. Maybe we just dont understand what you are asking for.Brad Barnhill
|
|
|
|
 |
|
 |
You might squeeze 3 people in an MG, but you cannot print 3 pixels in 2 dots. But you can print 2 digits with one Code 128 character...
|
|
|
|
 |