Monday, January 05, 2009
Home
.Net
Return of the Repeater
Complete image control & app
Part 2 - Starting the control
Part 3 - Loading images
Part 4 - Custom exceptions
Part 5 - Fax/Multipage tifs
Part 6 - Custom events
Part 7 - Selecting fax pages
Part 8 - Rotating displays
Part 9 - The power of GDI+
Part 10 - Zooming
Part 11 - .Net's fatal exception
Part 12 - Fix the squishies
Part 13 - Zoom to fit
Part 14 - You beat the pros
Part 15 - Cropping
Part 16 - Bonus: StickyMouse
Part 17 - Finishing touches?
Part 18 - Make the application
Part 19 - Adding viewports
Part 20 - A better toolbar
Part 21 - Connect the toolbar
Part 22 - Adding ImageEditors
Part 23 - Toolbar ZoomCombo
Part 24 - VB3 style ease
Part 25 - Saving images to files
Part 26 - Integer-only textBox
Part 27 - Passing save settings
Part 28 - The last exception
Part 29 - Menus offer more
Part 30 - Book, app & source
Couple of CS Snippets
XML processing quickies
File extension extensions
McAfee.Not
cs IntBox
Floating Holidays
Code snippets
Flexible sorts
Converted deserializations
Autodeploy not found
Autodeploy just stops
VB must be killed
Media file attributes
Fastest file searches
Webservicing custom objects
Aspect correct resize
Funky thumbnails
Wide interval timing
VB2005 or bust?
Recurring events
Single instances
Proper proper casing
Simple address formating
Combo filling reminder
Easy gradient forms
Grrrr on interops?
Winform memory usage
Windows service your ISP
Pretty up VS code printing
Remote configs with no BS
GDI+ printing cd cases
Your own flat combo
Where's the splitter?
Full autoemail
ReessppoonncceeWwrriittee
Kill the back cache
Color to hex
Source to web
Recode without recompile
Prop snippet for VS2008
Database tricks

Your own image control

Originally published December 2002 on DoItIn.net 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.


12) Fixing the squish

Now that you can see whole images, the oddly sized fax pages are probably bothering the heck out of you. The reason for the "squishes" is the Fax transmission compression.

When you send a fax you can specify different quality/speed settings typically called "Draft" and "High"; Different machines allow different settings but these two are usually in the list somewhere. The difference is the image resolution. Along with converting full color sources to 1bitperpixel black and white format, fax compression traditionally trims down the number of bits by reducing the number of vertical pixels. A rule of thumb way to think of it is that every other vertical scanline is being removed, vertical thinning being the least noticeably impactive on the eye. Due to geeky things it's not really halving the lines but the results are close enough that the analogy fits. To see this, right click and look at the advanced properties of our demo fax file and notice that the horizontal resolution is 204 but the vertical is only 98.

Because the compression technique is so common, Fax viewing applets such as the new Microsoft viewer or the older Wang and Kodak fax viewer applets automatically account for it and "put the pixels back". We have to do that too.

Open the ImageUtilities.vb file and wrap a conditional fix around the bmpDest constructor call (the bolded lines) of the CopyImage function:

...
    'make bitmap for result
If SourceImage.HorizontalResolution <> SourceImage.VerticalResolution Then
        bmpDest = New Bitmap(CInt(SourceImage.Width / SourceImage.HorizontalResolution) * 100, _
            CInt(SourceImage.Height / SourceImage.VerticalResolution) * 100)
   
    Else
        bmpDest = New Bitmap(SourceImage.Width, SourceImage.Height)
   
End If
...

Now if the source image's resolutions don't match, the destination bitmap width and height will be correctly adjusted. Remember that DrawImage is going to stretch the source graphic to fit the size of the destination bitmap so with this little calculation we're just correcting the destination area and DrawImage will fill in the gaps.

I'll mention up front that stretching the image this way will make the fully zoomed displays fuzzy. That's a result of the interpolation and there's not an easy way around it using GDI+ alone. You can try the different interpolation modes, multiplying the above calculations by 200 instead of 100, playing with the bmpDest.SetResolution method and get some minor enhancements but in the end using HighQualityBicubic and the display's native DotsPerInch setting ("DPI", as specified in you controller's advanced properties dialog) is best for all of the image types that the control will be displaying

Gotta change just one more thing. We coded LoadImage(img) so that it would only use the CopyImage function if a file had more than one pageframe, now we have to fix single page faxes so all image sources should be passed through the slicer. (Alternatively you could trust the file extension or even read the file headers, go for it if you feel very trusting.)

The update only requires removing the conditional from the array-filling section of LoadImage(img), trimming it down to this:

...

    ''reset the array to the number of pages
    ReDim m_ImagePages(pageCount - 1)

    For i As Integer = 0 To UBound(m_ImagePages)
        tmpFileImage.SelectActiveFrame(FrameDimension.Page, i)
        tmpFrameImage = DirectCast(tmpFileImage.Clone, Image)
        tmpFrameImage = CopyImage(tmpFrameImage)
        m_ImagePages(i).OriginalImage = tmpFrameImage
        m_ImagePages(i).WorkingImage = DirectCast(tmpFrameImage.Clone, Image)
        m_ImagePages(i).CurrentZoom = 100
        CalcZoomPercentLimits(m_ImagePages(i))
        
    Next

    UpdateZoomDisplay()

...

Next: Zooming to fit

Robert Smith
Kirkland, WA

 

added to smithvoice march 2005


Print  

pagecomment
  Add Comment



Submit Comment
  View Ratings
50.00%0
40.00%0
30.00%0
20.00%0
10.00%0

Number of Comments 0 , Average of Ratings
  View Comments
No comment.


Privacy Statement  |  Terms Of Use
Copyright 2008 by Robert C. Smith