Proportional resizing of an image

  • Thread starter Thread starter John
  • Start date Start date
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
 
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! |
*******************************************
 
Answered in the c# group. Please avoid to multipost (and crosspost only if
really needed)...
 
Back
Top