Introduction
The new millennium standard - JPEG2000 - has become more and more popular. It has many useful features and superior compression performance. Pictures, compressed with JPEG2000 are usually smaller, yet look better!
Unfortunately, there are almost no components or libraries that support VisualBasic. Most of them are aimed to C/C++ or Java. And writing your own JPEG2000 decoder completely in VisualBasic from scratch is, to put it mildly, impractical.
This article suggests an easy way to add JPEG2000 viewing capabilities to your VisualBasic application.
Background
"JPEG2000 is a new image-encoding standard than provides high compression with image quality superior to all existing standard encoding techniques. This high compression and quality performance is due to the adaptation of wavelet transforms. Wavelet transforms are mathematical formulas that represent complex structures in the image, thereby compressing an extremely large amount of image data into a relatively small amount of compressed data. This compression technique allows applications to save compressed images with higher compression ratios and better image quality as compared to any other software currently in production".
Using the Code
Probably the easiest way to display JPEG 2000 images is to use a special ActiveX control, which will do all the work for you. First of all, you need to download it from here or use its stripped version from the demo project of this article.
Here I'll show how to make it work with minimal programming.
1. Register the Control
Execute the following command:
regsvr32.exe j2k-control.dll
To unregister the control, you need to use:
regsvr32.exe /u j2k-control.dll
2. Add Component to your VB Toolbox
Right click on the toolbox, select "Components"
and mark the "J2K_Control 1.0 Type Library" check-box:
3. Place the Control on your Form
Using "J2" button,
draw a rectangle on your form, where the images will be displayed. You should see a white area with "J2K-Control" text in the center.
4. Finally, a Little Coding
Assuming your form has Form1
name and the J2K-Control has J2K_Codec1
name, add the following 2 lines into the Form_Load()
:
Private Sub Form_Load()
J2K_Codec1.OpenFile "test.j2k"
Form1.Caption = "J2K: " + CStr(J2K_Codec1.ImageWidth) + _
"x" + CStr(J2K_Codec1.ImageHeight)
End Sub
That's it! I told you - it's easy. :)
Now you can try to run your application and you should see the test.j2k image (included in the demo project).
NOTE: This control is free for your own use, but if you want to distribute your application publicly, you will need to purchase it.
For more information - please visit http://j2k-codec.com.
History
- 20th May, 2005 - Initial version