Proportional resizing of an image

J

John

Hi

I am using below code to proportionally adjust size of an image size to a
given max height & width. Problem is that image is deteriorated compared to
a similar operation in say MS Access report. Is there a better proportional
resizing function available that can maintain better image quality?

Many Thanks

Regards


Public Function ProportionallyResizeBitmap(ByVal src As Bitmap, ByVal
maxWidth As Integer, ByVal maxHeight As Integer) As Bitmap
' original dimensions
Dim w As Integer = src.Width
Dim h As Integer = src.Height
' Longest and shortest dimension
Dim longestDimension As Integer = If((w > h), w, h)
Dim shortestDimension As Integer = If((w < h), w, h)
' propotionality
Dim factor As Single = CSng(longestDimension) / shortestDimension
' default width is greater than height
Dim newWidth As Double = maxWidth
Dim newHeight As Double = maxWidth / factor
' if height greater than width recalculate
If w < h Then
newWidth = maxHeight / factor
newHeight = maxHeight
End If
' Create new Bitmap at new dimensions
Dim result As New Bitmap(CInt(newWidth), CInt(newHeight))
Using g As Graphics = Graphics.FromImage(DirectCast(result,
System.Drawing.Image))
g.DrawImage(src, 0, 0, CInt(newWidth), CInt(newHeight))
End Using
Return result
End Function
 
G

Gregory A. Beamer

I am using below code to proportionally adjust size of an image size
to a given max height & width. Problem is that image is deteriorated
compared to a similar operation in say MS Access report. Is there a
better proportional resizing function available that can maintain
better image quality?

Answered in C# group.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
P

Patrice

Answered in the c# group. Please avoid to multipost (and crosspost only if
really needed)...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top