473,386 Members | 1,828 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,386 software developers and data experts.

Getting the Dimensions and size of a Picture

I am trying to load a picture into an imagebox with stretch property set to true but the picture is showing in a disproportionate manner. I now wish to determine the width and height of the picture programmatically before loading so I can adjust my image box accordingly. Any ideas about how to do this?
Feb 21 '07 #1
2 1552
This code (from VB 2005) should point you in the right direction. This snippet is from one of my recent projects that randomly sizes an image, maintaining aspect ratio, upon a timer tick. The image I loaded into the picturebox was an image loaded into the project's resources store.

Expand|Select|Wrap|Line Numbers
  1. Dim iWidth As Integer = My.Resources.logo2_1280.Width
  2. Dim iHeight As Integer = My.Resources.logo2_1280.Height
  3. Dim iAspect As Single = iWidth / iHeight
  4.  
  5. Private Sub tmrMove_Tick(ByVal sender As System.Object, _
  6.                  ByVal e As System.EventArgs) Handles tmrMove.Tick
  7.  
  8.     Dim iNewWidth As Integer = Int(Rnd() * 500)
  9.     Dim sNewSize As New Size(iNewWidth, iNewWidth / iAspect)
  10.     Me.imgLogo.Size = sNewSize
  11.  
  12. End Sub
Feb 21 '07 #2
Killer42
8,435 Expert 8TB
I am trying to load a picture into an imagebox with stretch property set to true but the picture is showing in a disproportionate manner. I now wish to determine the width and height of the picture programmatically before loading so I can adjust my image box accordingly. Any ideas about how to do this?
If you first load it into a PictureBox with AutoSize property set to True, or an Imagebox with Stretch set to False, it will automatically adjust itself to the size of the loaded image. Then you can just read off the Width and Height properties.
Feb 22 '07 #3

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

Similar topics

17
by: John Hunter | last post by:
I have a largish data set (1000 observations x 100 floating point variables), and some of the of the data are missing. I want to try a variety of clustering, neural network, etc, algorithms on the...
2
by: duikboot | last post by:
Hi there, In Photoshop I can, when I want to change the dpi(dots per inch) of a picture, arrange that the picture won't be resized. Do you know of a way, I can accomplish this in python with...
0
by: Daron S. Lowell | last post by:
I need to be able to obtain the dimensions of some graphics files. Most of what I have found in this group seems to indicate loading the files into a form, then obtaining the dimensions form a...
1
by: Frank Rizzo | last post by:
How can I retrieve the dimentions of the image that's been loaded into a picture box? Thanks
12
by: Christian Blackburn | last post by:
Hi Gang, I would like to customize the installation's logo. What are the ideal dimensions for a BannerBitmap? MSDN just tells me how to use the properties window (ya like I didn't already know...
1
by: sympatico | last post by:
Hi, I am trying to compare 2 images to check if they are exactly identical (in terms of data), I thought this would be quicker than analysing pixels of the images. I have found lots of examples...
2
by: jodleren | last post by:
Hi! I am making an option, which opens a small window with a picture in it and data about it. I just want a JS script, which will get the picture size, and then set the window accordingly? ...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
6
by: Joaquim Amado Lopes | last post by:
Greetings. Is there any way, in Javascript, to put in 2 variables the width and height of a picture, given the filename and without the picture being displayed in the webpage? Thank you,...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.