473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Image resizing

37
I m using vb 2005. I m importing a jpeg format image into form2. The image on the form will be dependant on the CustomerID. The CustomerID is taken from form1. I am also trying to allow user to select the size of the image by addding a combo box named ComboBox1.
The following is my code:

Form2
--------------------------

Expand|Select|Wrap|Line Numbers
  1. Sub Image(Byval CustomerID As String)
  2.  Dim theImage As Image
  3.     Dim filespec As String
  4.     Dim scaleToPercent As Integer
  5.     Dim imageAdjustmentPercent As Decimal
  6.     Dim adjustedImageWidth, adjustedImageHeight As Integer
  7.  
  8.  filespec = "C:\Documents and Settings\Gary\My Documents\MP\" & CustomerID & ".jpeg"
  9.         theImage = Image.FromFile(filespec)
  10.  
  11.  imageAdjustmentPercent = (scaleToPercent / 100)
  12.  
  13.  
  14.         adjustedImageWidth = (theImage.Width * imageAdjustmentPercent)
  15.         adjustedImageHeight = (theImage.Height * imageAdjustmentPercent)
  16.         theImage = theImage.GetThumbnailImage(adjustedImageWidth, adjustedImageHeight, Nothing, Nothing)
  17.  
  18.         PictureBox1.Image = theImage
  19.  
  20.   Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  21. scaleToPercent=ComboBox1.Text
The image doesnt resize when the text in the comboxbox changed.
Can someone edit my code so that the image resize once the integer in the comboxbox change.(default integer in combobox is 100)
Aug 1 '07 #1
3 1371
I noticed that you called your sub "Image". The framework uses the "Image" keyword in the system.drawing. I don't know if it is your problem but I would definitely change the name to avoid mysterious bugs.
Aug 1 '07 #2
gyap88
37
I have changed the name of the sub but the problem still exist.

Expand|Select|Wrap|Line Numbers
  1. Sub DisplayImage(Byval CustomerID As String)
  2. Dim theImage As Image
  3. Dim filespec As String
  4. Dim scaleToPercent As Integer
  5. Dim imageAdjustmentPercent As Decimal
  6. Dim adjustedImageWidth, adjustedImageHeight As Integer
  7.  
  8. filespec = "C:\Documents and Settings\Gary\My Documents\MP\" & CustomerID & ".jpeg"
  9. theImage = Image.FromFile(filespec)
  10.  
  11. imageAdjustmentPercent = (scaleToPercent / 100)
  12.  
  13.  
  14. adjustedImageWidth = (theImage.Width * imageAdjustmentPercent)
  15. adjustedImageHeight = (theImage.Height * imageAdjustmentPercent)
  16. theImage = theImage.GetThumbnailImage(adjustedImageWidth, adjustedImageHeight, Nothing, Nothing)
  17.  
  18. PictureBox1.Image = theImage
  19.  
  20. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  21. scaleToPercent=ComboBox1.Text
I guess the problem is the failure to return scaleToPercent to sub DisplayImage.
Can anyone help me?
Aug 2 '07 #3
Killer42
8,435 Expert 8TB
Good point. You are trying to use the variable out of scope. It should be a form-level or global variable.
Aug 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jim | last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick) is a processor intensive exercise. I'm setting up a site where users will be uploading up to 10 images along with the details...
6
by: bissatch | last post by:
Hi, I have a collection of images stored in a DB. They are there for the purpose of a news system. When the user views the homepage it will diplay cropped versions of the news where the user...
3
by: Zahid Khan | last post by:
I need little help in my situation. I am reading a graphic file (jpg) from disk and then resizing it and save resized image. What happens, it gets blured, I want to retain same quality so that...
10
by: David W. Simmonds | last post by:
I have a DataList control that has an Image control in the ItemTemplate. I would like to resize the image that goes into that control. I have a series of jpg files that are full size, full...
8
by: berkshire | last post by:
Hi, Anyone know of a script out there that can resize images and not sacrifice image quality? I've been using phpthumb (http://phpthumb.sourceforge.net/) but when compared to an image resized...
9
by: tshad | last post by:
Is there a way to display images (imageButtons or linkbuttons for instance) as a max size (200px by 50px) and not have it stretch the image? What I want to be able to do is limit the real estate...
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
10
by: mishrarajesh44 | last post by:
hii all, I am facing a problem currently.. i have a script for image uploading and resizing.. the image uploading takes place properly for every size images.. but, the resizing works for...
11
by: shapper | last post by:
Hello, I am displaying an image on a few pages. The image size is 50 px height and 50 px width. In some pages I need the image to be 30x30 px in others 40x40 px and in others 50x50px. Can I...
14
anfetienne
by: anfetienne | last post by:
hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.