Click here to Skip to main content
Licence MIT
First Posted 11 Dec 2009
Views 12,876
Downloads 311
Bookmarked 24 times

Displaying Binary Images and Barcode

By RMostafa | 11 Dec 2009
This is an update to the RbmBinaryImage control - to display barcodes.

1
1 vote, 12.5%
2
1 vote, 12.5%
3
1 vote, 12.5%
4
5 votes, 62.5%
5
4.16/5 - 8 votes
μ 4.16, σa 2.13 [?]

Introduction

One of my friends was asking me how to display barcodes in ASP.NET. There is a great Open Source code written by Bart De Smet which can return a bar code image from a bar code string; you could see his article here. I have just added to it a small option of whether or not to display the code under the bar code. The library returns an Image. I thought, adding the display of the bar code from the bar code string value to RBMBinaryImage would be cool.

Background

In the last version of RBMBinaryImage on CodeProject, some people pointed out that the control worked in Visual Studio perfectly but not well on some servers. I place here a solution for this problem posted by Louis, on of the control users on my site for the RBMBinaryImage, for users using the old version.

  1. Open IIS and open the properties for the website you want the handler to work for.
  2. Open Handler mappings and select a file extension which is served by ASP.NET, like .aspx, and click Edit.
  3. Copy the file that's used over there (should be %windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll).
  4. Close the dialog and click Add Script Map... to add a new one. Put the copied value in the right textbox, and fill in .rbm as the extension you want to be handled - uncheck the option "Verify that file exists" when mapping the application extensions.
  5. Next, close all open boxes by clicking OK, and you should be ready to go.

In the new version of the control, we can display a barcode as an image. Shown below is a screenshot:

Using the code

The idea was simple since, the Code39 library returns an Image object, so I only got its bytes and passed it to the ImageContent property, which is then rendered in the image. For more information on how the binary image display works in RBMBinaryImage, please see the post here. Again, the usage of the control is very easy. To display the barcode, you only need to set the PrintBarcode property to true, and pass to the BarCodeValue the barcode. As you can see below, the DisplayThumbnail property is still being applied on the bar code.

<Rbm:RbmBinaryImage ID="RbmBinaryImage2" runat="server" 
    PrintBarcode="true"  BarCodeValue='<%# Eval("BarCode") %>' 
    DisplayThumbnail="true"   ThumbnailSize="160" 
    EmptyImageUrl="images/NoPhoto.JPG" />

I have made a change to the HttpHandler to be with the extension .ashx instead of .rbm, to be standard compliant.

<httpHandlers>
  <add verb="GET" path="__RbmImageHandler.ashx" type="RbmControls.RbmImageHandler"/>
</httpHandlers>

Finally

You can download the latest version of the project from here.

License

This article, along with any associated source code and files, is licensed under The MIT License

About the Author

RMostafa

Software Developer (Senior)
Code Republic
Egypt Egypt

Member
My name is Ramy Mostafa. I’m From Alexandria,Egypt currently living in Cairo,Egypt. I have graduated from the Arab Academy for Science and Technology and Maritime Transport with a BS. in Computer Science, also I’m a Microsoft Certified Professional since 2004. I have extensive professional experience as a developer and expertise in OOP, OOA, OOD and problem solving techniques. Currently I’m working as a senior developer in Code Republic a European owned and directed software outsourcing company based in Egypt with liaison offices in Europe.
 
Also I’m a huge fan of Al-Ahly Club, I like reading, swimming and diving -used to play in the national team of finswimming in Egypt- worth to mention that I like reading Ragol El Mostahel and Malaf el Mostakbal (a huge fan of it actually Smile | :) )
 
To reach me, you can either send me an e-mail at ramy.mostafa@gmail.com or call at (002) 010 3332382

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralBarCode Image Format PinmemberZ@clarco0:13 23 Nov '10  
Question[My vote of 2] Article Intro Purpose Pinmemberstixoffire3:30 15 Dec '09  
AnswerRe: [My vote of 2] Article Intro Purpose PinmemberRMostafa3:34 15 Dec '09  
GeneralRe: [My vote of 2] Article Intro Purpose Pinmemberstixoffire3:52 15 Dec '09  
GeneralRe: [My vote of 2] Article Intro Purpose PinmemberRMostafa4:50 15 Dec '09  
Well basically lets think of the first version that, a normal Image control isn't able to directly display Binary Image from the database so you tend to make a handler and pass for the image the URL of the handler and the id of the image you want to display. so the first version was an enhanced image control that would let you display by direct binding a database image you could write in C# code for ex. RbmBinaryImage1.ImageContent = FileUpload1.FileBytes; and the image will be displayed also you could bind the image field from the database directly to the ImageContent Property. This was the main functionality so there was some other added functionality like getting a thumbnail from this image, displaying a specified empty image if there is no content.
 
Then in this version, I've added that the control could display directly BarCode since normally for displaying the bar code image from most of the libraries they return an Image which still would need a specified handler for it. so instead of using two things you could now use this image control to directly display bar code by binding to it the code you want to generate the bar code for it. and yet you could use the other functionality like getting a thumbnail from this bar code etc.
 
Regards
[Ramy Mostafa]
GeneralArtice needs emprovment Pinmemberemilio_grv6:18 11 Dec '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 11 Dec 2009
Article Copyright 2009 by RMostafa
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid