locked
reduce image file size without losing quality RRS feed

  • Question

  • User944339287 posted

    hi guys.. the following url is my reference site:
    https://www.aspdotnet-suresh.com/2011/05/how-to-resize-size-image-without-losing.html

    I having an issue while converting to vb using https://converter.telerik.com/
    Error Message: Type of 'image' cannot be inferred from an expression containing 'image'

        Private Sub GenerateThumbnails(ByVal scaleFactor As Double, ByVal sourcePath As Stream, ByVal targetPath As String)
            Using image = Image.FromStream(sourcePath)
                Dim newWidth = CInt((image.Width * scaleFactor))
                Dim newHeight = CInt((image.Height * scaleFactor))
                Dim thumbnailImg = New Bitmap(newWidth, newHeight)
                Dim thumbGraph = Graphics.FromImage(thumbnailImg)
                thumbGraph.CompositingQuality = CompositingQuality.HighQuality
                thumbGraph.SmoothingMode = SmoothingMode.HighQuality
                thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic
                Dim imageRectangle = New Rectangle(0, 0, newWidth, newHeight)
                thumbGraph.DrawImage(image, imageRectangle)
                thumbnailImg.Save(targetPath, image.RawFormat)
            End Using
        End Sub




    Sunday, April 19, 2020 8:56 AM

Answers

  • User288213138 posted

    Hi kengkit,

    Using image = Image.FromStream(sourcePath)

    As mbanavige said, you should fully qualify the name.

    The C # code in the link you provided is problematic, It should be the following code, and then you will convert it to vb code.

    C#:
    var image = System.Drawing.Image.FromStream(sourcePath)
    
    VB:
    Dim image = System.Drawing.Image.FromStream(sourcePath)

    More information about Image.FromStream Method you can refer to this link:

    https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.fromstream?view=netframework-4.8

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2020 2:03 AM

All replies

  • User-158764254 posted

    I can't see if you imported the Sytem.Drawing namespace.  Could just fully qualify the name.

    Using image As System.Drawing.Image = System.Drawing.Image.FromStream(sourcePath)

    Sunday, April 19, 2020 10:54 AM
  • User288213138 posted

    Hi kengkit,

    Using image = Image.FromStream(sourcePath)

    As mbanavige said, you should fully qualify the name.

    The C # code in the link you provided is problematic, It should be the following code, and then you will convert it to vb code.

    C#:
    var image = System.Drawing.Image.FromStream(sourcePath)
    
    VB:
    Dim image = System.Drawing.Image.FromStream(sourcePath)

    More information about Image.FromStream Method you can refer to this link:

    https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.fromstream?view=netframework-4.8

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2020 2:03 AM