Results 1 to 17 of 17

Thread: Changing an Image Size

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    87

    Changing an Image Size

    Firstly I am still using the 2013 version of vb.net

    I am writing an image processing routine and after 50 or so images it kept running out of memory because Bitmaps are memory hogs and hang around apparently

    Anyway this works and may be useful for others

    Code:
    Public Function ImageSizeChangeLBF(imgSource As Image, intWidth As Integer, intHeight As Integer) As Image 
      ' Written 5th March 2014
    
      Dim memStream As New MemoryStream          ' MUST go outside the Using Statements
    
      ' Make a bitmap for the Destination
      Using bmpDestination As New Bitmap(intWidth, intHeight)
    
        ' Make a Graphics object for the Destination Bitmap.
        Using gphDesination As Graphics = Graphics.FromImage(bmpDestination)
    
          ' Copy the source image into the Destination bitmap with different Dimensions
          gphDesination.DrawImage(imgSource, 0, 0, intWidth + 1, intHeight + 1)
    
          ' Copy to a Memory Stream (CANNOT JUST SET IMAGE = BITMAP AS THIS IS JUST MEMORY AND IT IS RESET BY "END USING")
          bmpDestination.Save(memStream, System.Drawing.Imaging.ImageFormat.Bmp)
    
        End Using
      End Using
    
      '  Return
      ImageSizeChangeLBF = Image.FromStream(memStream)
    
    End Function
    So just do this

    picBox.Image = ImageSizeChangeLBF(picBox.Image, intWidth, intHeight )

    Hope this helps somebody
    Bob

    Ps You need: Imports System.Drawing
    .
    Last edited by wavering; Mar 5th, 2021 at 07:04 AM.

Tags for this Thread

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