Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:40:28+00:00 2026-05-15T14:40:28+00:00

After searching, I’ve discovered this code: Public Sub ResizeImage(ByVal scaleFactor As Double, ByVal fromStream

  • 0

After searching, I’ve discovered this code:

Public Sub ResizeImage(ByVal scaleFactor As Double, ByVal fromStream As Stream, ByVal toStream As Stream)
    Dim image__1 = System.Drawing.Image.FromStream(fromStream)
    Dim newWidth = CInt(image__1.Width * scaleFactor)
    Dim newHeight = CInt(image__1.Height * scaleFactor)
    Dim thumbnailBitmap = New System.Drawing.Bitmap(newWidth, newHeight)

    Dim thumbnailGraph = System.Drawing.Graphics.FromImage(thumbnailBitmap)
    thumbnailGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
    thumbnailGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
    thumbnailGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

    Dim imageRectangle = New System.Drawing.Rectangle(0, 0, newWidth, newHeight)
    thumbnailGraph.DrawImage(image__1, imageRectangle)
    thumbnailBitmap.Save(toStream, image__1.RawFormat)

    thumbnailGraph.Dispose()
    thumbnailBitmap.Dispose()
    image__1.Dispose()
End Sub

There are 2 things I can’t “modify” to solve my problem:

  1. I wouldn’t like to pass a stream, but I prefer to pass a path like C:\mysite\photo\myphoto.gif. How can I “convert” it to accept a file and not a stream?
  2. In this function I’ve to pass a “scale” value. But I prefer to check if the image is too big (for example > 1024x768) than resize it to a max of 1024x768. How can I check this with System.Drawing.

As you can see I don’t know anything about System.Drawing so I need an “hard” help to solve this job.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:40:29+00:00Added an answer on May 15, 2026 at 2:40 pm

    Here is some c# code I did about 5 years ago to do this (it should still work I hope as the app hasn’t been touched since). I think it does everthing you need but it doesn’t upscale the image to 1024×768 if it is smaller. This code will only make sure that if it is larger than 1024×768, it will resize proportionally to fit within those dimensions:

    const int maxWidth = 1024;
    const int maxHeight = 768;
    Image newImage = Image.FromFile("YourPicture.jpg");
    double percentToShrink = -1;
    if (newImage.Width >= newImage.Height)
    {
        // Do we need to resize based on width?
        if (newImage.Width > maxWidth)
        {
            percentToShrink = (double)maxWidth / (double)newImage.Width;
        }
    }
    else
    {
        // Do we need to resize based on width?
        if (newImage.Height > maxHeight )
        {
            percentToShrink = (double)maxHeight  / (double)newImage.Height;
        }
    }
    
    int newWidth = newImage.Width;
    int newHeight = newImage.Height;
    
    // So do we need to resize?
    if (percentToShrink != -1)
    {
        newWidth = (int)(newImage.Width * percentToShrink);
        newHeight = (int)(newImage.Height * percentToShrink);
    }
    
    // convert the image to a png and get a byte[]
    MemoryStream imgStream = new MemoryStream();
    Bitmap bmp = new Bitmap(newWidth, newHeight);
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.InterpolationMode =   System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.FillRectangle(System.Drawing.Brushes.White, 0, 0, newWidth, newHeight);
        g.DrawImage(newImage, 0, 0, newWidth, newHeight);
    }
    
    // This can be whatever format you need
    bmp.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png);
    byte[] imgBinaryData = imgStream.ToArray();
    imgStream.Dispose();
    

    If you need to convert this to VB.NET, you can use the C# to VB.NET converter here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After searching lot on the internet we have found following code to get only
After searching online, the best solution I've found so far is to just make
After searching around somewhat thoroughly, I noticed a slight lack of functions in PHP
After searching around a bit and consulting the Dinosaur Book, I've come to SO
After searching a lot, reading every tutorials I've found and asking some questions here,
After searching for a while in books, here on stackoverflow and on the general
After searching online and going through past stackoverflow posts for a suitable implementation for
After searching through some existing libraries for JSON, I have finally ended up with
After searching a lot i did not get any answers and finally i had
After searching a long time for a performance bug, I read about denormal floating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.