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 7515185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:43:26+00:00 2026-05-30T00:43:26+00:00

How do I add constraints to image resizing code? I want the image to

  • 0

How do I add constraints to image resizing code? I want the image to be no larger then 165×146. The below code does not hold the constraint when image is 525×610

        intWidth = 165 '*** Fix Width ***'  
        intHeight = 146 '*** Fix Width ***' 

            If objGraphic.Width > intWidth Then
                Dim ratio As Double = objGraphic.Height / objGraphic.Width
                intHeight = ratio * intWidth
                objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
            ElseIf objGraphic.Height > intHeight Then
                Dim ratio As Double = objGraphic.Width / objGraphic.Height
                intWidth = ratio * intHeight
                objBitmap = New Bitmap(objGraphic, intWidth, intHeight)
            Else
                objBitmap = New Bitmap(objGraphic)
            End If
  • 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-30T00:43:29+00:00Added an answer on May 30, 2026 at 12:43 am

    I think you want to maintain the aspect ratio of your image? If so, this method might be appropriate; you will need to multiply the width and height by the ratio you obtain.

    'define max size of image
    intWidth = 165
    intHeight = 146
    
    'if the width/height is larger than the max, determine the appropriate ratio
    Dim widthRatio as Double = Math.Min(1, intWidth / objGraphic.Width)
    Dim heightRatio as Double = Math.Min(1, intHeight / objGraphic.Height)
    
    'take the smaller of the two ratios as the one we will use to resize the image
    Dim ratio as Double = Math.Min(widthRatio, heightRatio)
    
    'apply the ratio to both the width and the height to ensure the aspect is maintained
    objBitmap = New Bitmap(objGraphic, CInt(objGraphic.Width * ratio), CInt(objGraphic.Height * ratio))
    

    Edit: Probably need to explicitly convert new height and width to ints

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

Sidebar

Related Questions

Does a Foreign Key referencing a Primary Key need the NOT NULL constraint in
mysql> ALTER TABLE category ADD CONSTRAINT category_parent_category_id FOREIGN KEY (parent) REFERENCES category(id); ERROR 1005
What is the difference between the following two statements? alter table [dbo].[Demo] add constraint
In Ruby on Rails, how to add foreign key constraint in migration?
I wish to add some type of business logic constraint to a table, but
This is the constraint I have on the Customers table. ALTER TABLE Customers ADD
Add service reference to Amazon service fails, saying Could not load file or assembly
Quick add on requirement in our project. A field in our DB to hold
We add Struts errors and messages using ActionSupport.addActionError(...) and addActionMessage(...) and then output the
I'm trying to add constraints checking, as described here How to specify the cardinality

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.