Results 1 to 4 of 4

Thread: A simple function for resizing an image

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    74

    A simple function for resizing an image

    VB Code:
    1. Public Function ResizeImage(ByVal iImage As Bitmap, ByVal ScaleX As Single, ByVal ScaleY As Single, ByVal iMode As InterpolationMode) As Bitmap
    2.         'Receives an image as input and scales it up or down
    3.         Dim g As Graphics
    4.         Dim sImage As Bitmap = New Bitmap(CInt(iImage.Width * ScaleX), CInt(iImage.Height * ScaleY))
    5.         g = Graphics.FromImage(sImage)
    6.         g.InterpolationMode = iMode
    7.         g.DrawImage(iImage, 0, 0, sImage.Width, sImage.Height)
    8.         ResizeImage = sImage
    9. End Function
    SYNTAX:
    Where MyResizedImage is a bitmap
    MyResizedImage = ResizeImage(iImage, ScaleX, ScaleY, iMode)

    PARAMETERS:
    iImage is the bitmap image to be resized
    ScaleX is the percentage to multiply the original width
    ScaleY is the percentage to multiply the original height
    iMode is the desired interpolation mode
    Last edited by AlphaScorpious; Jan 28th, 2007 at 03:04 AM.

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: A simple function for resizing an image

    wouldnt it work better if you change:
    VB Code:
    1. Public Function ResizeImage(ByVal iImage As Bitmap, ByVal ScaleX As Single, ByVal ScaleY As Single, ByVal iMode As Integer) As Bitmap

    to:
    VB Code:
    1. Public Function ResizeImage(ByVal iImage As Bitmap, ByVal ScaleX As Single, ByVal ScaleY As Single, ByVal iMode As InterpolationMode) As Bitmap
    2.  
    3. g.InterpolationMode = iMode

    ?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    74

    Re: A simple function for resizing an image

    Quote Originally Posted by JuggaloBrotha
    wouldnt it work better if you change:
    VB Code:
    1. Public Function ResizeImage(ByVal iImage As Bitmap, ByVal ScaleX As Single, ByVal ScaleY As Single, ByVal iMode As Integer) As Bitmap

    to:
    VB Code:
    1. Public Function ResizeImage(ByVal iImage As Bitmap, ByVal ScaleX As Single, ByVal ScaleY As Single, ByVal iMode As InterpolationMode) As Bitmap
    2.  
    3. g.InterpolationMode = iMode

    ?
    That's the difference between a programmer and someone who can program.

    The original code has been edited to implement JuggaloBrotha's suggestion.

  4. #4
    Banned
    Join Date
    Jun 2013
    Posts
    1

    Re: A simple function for resizing an image

    hhh, i am just looking for a method to resize images, now i get it. tks, guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width