473,524 Members | 3,050 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dealing with images

Hi,

I have a picture box control on my winform, and it is of course fixed to a
certain height and width.

Users can load and view images of many sizes, and the only way I can deal
with this is to set the picture box sizemode to be centerimage. This does
however stretch the image out to the height and width of the control. which
usually screws up the image

is there a way to have the image display in the center where it is resizedd
keeping its perspective but showing the image in total?

Thanks
Nov 23 '05 #1
1 1016
I use the following routine to resize the picture box to display the image
centered within the original size of the picture box while maximizing the
image size as much as possible. Note that MxSz is the original size of the
picture box and the function returns the new size and location to which the
picture box can be set.

Private Function get_NewImgSize(ByVal OldImage As Image, ByVal MxSz As
Size) As Size
Dim w As Integer = OldImage.Width
Dim h As Integer = OldImage.Height
Dim nw, nh As Integer
Dim wtoh As Double = w / h
If (w >= MxSz.Width AndAlso h <= MxSz.Height) Then
nw = MxSz.Width
nh = CInt(nw / wtoh)
ElseIf h >= MxSz.Height AndAlso w <= MxSz.Width Then
nh = MxSz.Height
nw = CInt(nh * wtoh)
ElseIf w >= MxSz.Width AndAlso h >= MxSz.Height Then
If (w - MxSz.Width) >= (h - MxSz.Height) Then
nw = MxSz.Width
nh = CInt(nw / wtoh)
Else
nh = MxSz.Height
nw = CInt(nh * wtoh)
End If
Else
'Both are smaller
If (MxSz.Width - w) >= (MxSz.Height - h) Then
nw = MxSz.Width
nh = CInt(nw / wtoh)
Else
nh = MxSz.Height
nw = CInt(nh * wtoh)
End If
End If
Return New Size(nw, nh)
End Function
--
Dennis in Houston
"Aussie Rules" wrote:
Hi,

I have a picture box control on my winform, and it is of course fixed to a
certain height and width.

Users can load and view images of many sizes, and the only way I can deal
with this is to set the picture box sizemode to be centerimage. This does
however stretch the image out to the height and width of the control. which
usually screws up the image

is there a way to have the image display in the center where it is resizedd
keeping its perspective but showing the image in total?

Thanks

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1671
by: paul | last post by:
hey there all! i'm writing some little programs, and i'd like to know about how to deal with directories on unix. i've read up on this, but the docs don't really mention much on it. do i use the pickle module, or something? what i'd like to do is read in a path, say /home/username/images/ and that path contains a dir called downloads and...
7
2354
by: Wayne | last post by:
I have a script that uses filesystemobject that reads files from a given path, in my case images. It is running on a server that is 2000 adv svr w/ all current patches. The script prior to some patch updating worked fine and showed the pictures. Now the pictures no longer show when looking at the source code the absolute path of the file is...
1
2384
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to create a form, a button (Button1) and an Picture Box (picBox). "watermark.jpg" is any jpg image, "beispiel.tif" is a multipage TIFF image with the...
3
3813
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a nutshell when testing my ASP.NET (localhost) apps images randomly don't load on the page. Examining the IIS logfile shows the missing images give 401 or...
9
1343
by: Mark Olbert | last post by:
Has anyone found useful tutorials on how to deal with the shortcomings of master pages, specifically, the fact that they don't handle HTML file references when used to create web pages anywhere other than the root folder of a website? I'm familiar with using the runat="server" workaround for img tags (and supposedly that works for <a> tags,...
4
2952
toxicpaint
by: toxicpaint | last post by:
Hi, can anyone give me a hand. I'm currently displaying 4 random images at the top of a page. I did this using an array of 35 pictures and then writing them to page. The problem I have is that in theory you could get the same image 4 times. I quite often get 2 of the same picture come up. What's the easiest way of saying "once an image is...
5
4087
by: remon87 | last post by:
I need some help. I have javasript that creates the submenu but it works if I have a text with css. I need it to do the same with a roll over images. so when I click on the image the submenu (images) shows with roll overs as well. That's what I have... <script type="text/JavaScript"> <!-- function MM_swapImgRestore() { //v3.0 var...
4
1931
by: CdnRebel | last post by:
Hi, I have double checked and triple checked, but I cannot figure out why my second image (the picture in div.top2) is not displaying. The spelling is right. I have attached the files. Also is there a way of aligning all the pictures towards the centre with the wording beneath lined up nicely as well? Thanks for any help, Mary ...
0
7248
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7472
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7636
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5772
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5167
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4810
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3308
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1694
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.