|
-
Sep 13th, 2005, 12:30 PM
#1
Thread Starter
Fanatic Member
resize an image
Hi! I'd like to know if it is possible to resize an image, loaded at runtime, to fit the picturebox dimension but keeping the proportions. But I don't want to copy it resized... I have an images in a folder, that I load to 3 to 4 different place in the application, the picturebox not being the same size everywhere, I need to only resize it, not make a resized copy of the image... is that clear enough, do you understand what I mean!???
-
Sep 13th, 2005, 12:49 PM
#2
Re: resize an image
Hi,
Not directly, if I understand you correctly. You can use the stretchmode on a picturebox, but then the picture will lose proportions. I reckon the best way to do it would be to put a second picturebox inside the first to hold the picture and compare the ratio of the sides of your outer "container" picturebox (fixed size) to your desired picture (could be anything). From that, you can figure out whether to set the inner picturebox to be the same as the width of (and hence of smaller height than) the outer picturebox, or to set it to be the same height as (and hence smaller width than) the outer picturebox. Then set the size of the inner picturebox and stretch your picture to fit that.
Does that make sense?
zaza
-
Sep 13th, 2005, 01:01 PM
#3
Fanatic Member
Re: resize an image
Just draw the image yourself using a Graphics object in the paint event of a picturebox or a panel or whatever. Calculating the new dimensions is not hard.
"so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman
-
Sep 13th, 2005, 01:15 PM
#4
Thread Starter
Fanatic Member
Re: resize an image
ok, I have this. It works fine with small size picture. But when I try with a full hi res picture @5mo, (what the application I'm designing is intended to) it crashes running out ot memory...
VB Code:
Public Sub ResizeToRatio(ByRef p As PictureBox)
Dim i As Image = p.Image
Dim b As Bitmap
Dim h, w As Double
Dim ratio As Double = i.Width / i.Height
'
h = i.Height
w = i.Width
'
b = New Bitmap(i, w, h)
'
While ((b.Width > p.Width) Or (b.Height > p.Height))
w -= 1.0 * ratio
h -= 1.0
b = New Bitmap(i, w, h)
End While
'
p.Image = b
p.SizeMode = PictureBoxSizeMode.CenterImage
End Sub
-
Sep 13th, 2005, 01:36 PM
#5
Fanatic Member
Re: resize an image
I imagine it happens here:
VB Code:
While ((b.Width > p.Width) Or (b.Height > p.Height))
w -= 1.0 * ratio
h -= 1.0
b = New Bitmap(i, w, h)
End While
where you are creating a new bitmap numerous times.
You should just make sure that you have that image in memory, and then paint it over the picturebox when its Paint event fires.
"so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman
-
Sep 13th, 2005, 01:53 PM
#6
Thread Starter
Fanatic Member
Re: resize an image
ok, well in memory, you mean, a memorystream!?
its a path + filename I retreive from a dataset, so I shlould put it in a memory stream and then paint the resize... I'm sorry, I'm really not good with GDI+....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|