Y'herd thisun? 

“I’m nauseatingly pro-American. It is where great things are possible.”

by Elon Musk

Your own image control and App part 14

TaggedCoding, VB, Imaging

Originally published December 2002 on using VB7.0/2002. Updated for VB7.1 February 2005

Links for compiled demo versions, all required resources and source code are included at the end of this article.

Plus, get the complete eBook in Adobe Acrobat 7 format ... all here.


14) You're already beating the Pros

Before we move on to Cropping, look at just how well you've made your control so far. Let's compare even the current functionality of Loading, Rotating and Zooming with similar features in a couple of "Real" imaging applications: Jasc's PaintShop Pro and Microsoft's "Windows Picture and Fax Viewer".

Jasc's PaintShop Pro is a great semi-pro tool. It does nearly all that Adobe PhotoShop does at nearly the same quality (if not exactly the same) and more people use it because the brand-name "Jasc" doesn't yet carry the price of a tool with the "Adobe" logo. When you use File>New in PSP you can seemingly create a new graphic in any resolution at any color depth ...up to a maximum of 32767.

Already we see that Jasc makes its limits more true than .Net does. There's no "you can go to two billion and we'll just change it without telling you" silliness going on. :) However, the OS brick wall is still there. No matter what color depth you choose for the graphic you can't really hit 32767x32767; .Net VB6, C++, all are limited by the power of Windows paint messages.

And look what happens when you use a back door to blow past the size limits. I created an 8bit (256 color) graphic at 16900x16900. On my 2.8Ghz machine this takes the program a few seconds but it works. Once the image is displayed, I'll use Image>>Increase color depth>>16bit. After many seconds of chunking up pops that exception again.

While this isn't technically a full crash it may as well be because when you hit ok on the message your image and app are hosed. The image won't repaint and clicking on any menu or button hangs PSP as "Not Responding". You'll need to call up Task Manager to dump the process... and if you had a lot of changes in the queue you might have to do a full reboot to free up the system resources and get your overall performance back. Given the choice, an immediate .Net crash backed up by the CLR's garbage collector gets you back to work faster, not that we have to make a choice at all because our code won't hit the exception in the first place.

On the plus side for PSP, once you get an image, even a big one, Jasc allows you to Zoom in quite a bit farther than our 16bit maximum. Their zoom goes all the way up to 5000%. Most likely this is done with GDI32 equivalents of DrawImage, holding a buffer bitmap and quickly blasting a display representation of the desired source area. We could do this too if we wanted, doublebuffering is fast even with GDI+ and if we were out to do a full imaging tool that really needed to zoom that far then we could.

Now let's look at Microsoft's home-made XP/2003Server replacement for the licensed Wang and Kodak Fax Imaging controls that we had in previous versions: The "Windows Picture and Fax Viewer". This is a very cute little guy and while it's "free with the OS" I would have paid a buck more for Windows if it were less cute and more well made.

Pick an image on your machine and make a copy of it then start the viewer. Drag & drop the image copy to the applet to load it then click on either of the two sole, solitary 90degree-only rotate buttons (Our control offers a lot more options but a dev-user might only expose 90s. Maybe.).

What's the weirdness here ... Rotate counterclockwise is on the right, and rotate clockwise is on the left. Ok, it's not something our control deals with per se but it's weird (maybe the applet was made in a RightToLeft country to save money). Ignoring that you hit the button and if you're lucky you get a warning:

Microsoft's app is a destructive viewer. There is a save button on the toolbar but it's worthless because any rotations you apply will immediately overwrite your source file. And here's the kicker for business users: Rotating a Fax Tif doesn't give you that warning at all, it just automatically alters your original.

Chalk one up for your control, it may have been a pain to hold backups of our source images in memory but in the end the way we did it is just plain smarter.

Now let's look at those zoom buttons. Try to ignore that these also are in illogical order for a LeftToRight-centric Locale, with the ZoomPlus on the left and the ZoomMinus on the right (I've seen no other US/European imaging tool do that) and hit the ZoomPlus button repeatedly. Eventually you will hit a limit, but the app doesn't make it at all obvious, the image just stops growing. There's no status information and the buttons don't ever become disabled, matter of fact the always-enabled ZoomMinus button won't let you zoom out past the original size.

Again, it's not an apples to apples comparison because our control doesn't lock a dev-user into a GUI, we expose only the zoom properties and leave the user interface up to them. However, we do go out of our way to raise not only the current zoom percentage but also the hitMin and hitMax flags so a dev would have to be mighty lazy to not hook the button enabled properties up to the event and give the user an obvious cue to stop pressing the zoom buttons. Chalk another - a few others - up for our side.

And there's one more plus for us worth mentioning: Display smoothness. Zoom into an image in the Microsoft viewer so that the scrollbars shrink to let you slide the display around, and slide it around. Even on my 3.06HT with 128MBRadeon it's choppy. It's almost like the applet waits till you're done moving the bar before it does a redraw of the visible area. This implies that they're buffering a memory bitmap and drawing the visible area on demand (I wouldn't bank on that because if were holding a memory bitmap, why would they overwrite the source files? If they are using a memory bitmap for zooms then they're not doing it very well. Look at the smoothness when scrolling a large image display in your UC, we've done it via RAD and we get a better result. (Remember, MS can't blame GDI+ for their stuttering performance because their app wasn't written in .Net.)

Bottom line: Your control is at least on par, and in some ways better, at the basics than "Real" imaging tools.

Now let's finish it up.

Next: Cropping

Robert Smith
Kirkland, WA

added to smithvoice march 2005

jump to:

  • 1) The spec
  • 2) Setting up the workspace
  • 3) Feature 1: Loading an image
  • 4) Custom Exceptions
  • 5) "Fax images" and Multipage TIFFs
  • 6) Custom events
  • 7) Selecting specific fax pages
  • 8) Feature 2: Rotating image displays
  • 9) The most useful tool in GDI+: DrawImage
  • 10) Feature 3: Zooming
  • 11) Handling the unhandleable exception
  • 12) Fixing the squish
  • 13) Zooming to fit the control
  • 14) You're already beating the Pros
  • 15) Feature 4: Cropping
  • 16) Bonus Feature: StickyMouse
  • 17a) Final Cleanup
  • 17b) Passing the current display image
  • 18) Making the application
  • 19) Source and result viewports
  • 20) A better toolbar
  • 21) Hooking the toolbar to the project
  • 22) Adding ImageEditors
  • 23) The toolbar ZoomCombo
  • 24) The final solution
  • 25) Saving to image files
  • 26) An integer-only textbox
  • 27) Passing save options between forms
  • 28) Dealing with that last exception
  • 29) Offer more options with menus
  • 30 The downloads and ebook

  • home     who is smith    contact smith     rss feed π
    Since 1997 a place for my stuff, and it if helps you too then all the better