|
-
May 19th, 2006, 06:40 PM
#1
Thread Starter
Frenzied Member
change image size
I have an image that I want to resize, but the property is read-only. I tried creating a bitmap and setting it equal to the image, but that didn't work:
Code:
Dim bmp As Bitmap = New Bitmap(x, y)
bmp = pbBefore.Image
pbBefore.Image = bmp
How can I achieve my goal without looping through and drawing each pixel up to a certain length?
-
May 19th, 2006, 07:00 PM
#2
Frenzied Member
Re: change image size
VB Code:
Dim b As New Bitmap(w, h)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(pbx.Image)
g.Dispose()
pbx.Image = b
I typed this in i.e, so there may be a few errors.
-
May 19th, 2006, 07:25 PM
#3
Thread Starter
Frenzied Member
Re: change image size
Thanks. This is what I have now:
Code:
Dim b As New Bitmap(x, y)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(pbAfter.Image, New Point(0, 0))
g.Dispose()
pbAfter.Image = b
It almost does what I want, but not quit. It increases the drawing surface, which is half of what I want. The actual image doesn't resize. It stays the same and the new area is filled with grey. Any ideas on how to fix that?
-
May 19th, 2006, 08:12 PM
#4
Re: change image size
specify the new image size with a rectangle then draw your image in that rectangle
VB Code:
Dim ImageRect as new Rectangle([I]your rectangle coords[/I])
g.Graphics.DrawImage(pbAfter.Image, ImageRect)
I think that should do it
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 19th, 2006, 08:44 PM
#5
Thread Starter
Frenzied Member
Re: change image size
Excellent! That worked perfectly!
Thanks kevin.
-
May 19th, 2006, 08:57 PM
#6
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 23rd, 2006, 07:15 PM
#7
Thread Starter
Frenzied Member
Re: change image size
ahh, kebo, I've got another problem with that now. It's warping the images really bad when I resize them.... Is there some way of getting around this?
-
May 24th, 2006, 05:59 AM
#8
Re: change image size
 Originally Posted by System_Error
ahh, kebo, I've got another problem with that now. It's warping the images really bad when I resize them.... Is there some way of getting around this?
Well, have a look at this:
VB Code:
Private Sub CreateThumbGenie()
Dim NewImage As Image = Image.FromFile("filename")
' Make a bitmap for the result.
Dim DestSize As New Bitmap( _
CInt(PictureBox1.Width), _
CInt(PictureBox1.Height))
' Make a Graphics object for the result Bitmap.
Dim GenDest As Graphics = Graphics.FromImage(DestSize)
' Copy the source image into the destination bitmap.
GenDest.DrawImage(NewImage, 0, 0, _
DestSize.Width + 1, _
DestSize.Height + 1)
' Display the result.
PictureBox1.Image = DestSize
End Sub
'later in a command button, you can call it as:
[b] CreateThumbGenie()[/b]
This will create a smaller representation of the picture, without distorting
Hope it helps..
VB.NET MVP 2008 - Present
-
May 24th, 2006, 02:35 PM
#9
Thread Starter
Frenzied Member
Re: change image size
Thanks. I figured out the problem. I was thinking your code was again, causing a distortion, but it's not. I am using a numeric ticker that updates automatically. When it updates automatically I get the distortion. If I enter the value in myself, and then click enter, everything is fine. Is it like, painting over top of each of the images? How can I fix that?
THanks for the help.
-
May 24th, 2006, 03:16 PM
#10
Re: change image size
not really sure....maybe you can post some code?
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 24th, 2006, 03:38 PM
#11
Thread Starter
Frenzied Member
Re: change image size
Sure...
This is the handle_resize method which does all the resizing:
Code:
If x > 0 And y > 0 Then
Dim NewImage As Image = pbAfter.Image
' Make a bitmap for the result.
Dim DestSize As New Bitmap(x, y)
' Make a Graphics object for the result Bitmap.
Dim GenDest As Graphics = Graphics.FromImage(DestSize)
' Copy the source image into the destination bitmap.
GenDest.DrawImage(NewImage, 0, 0, _
x, _
y)
' Display the result.
pbAfter.Image = DestSize
End If
Now, it is called EACH time the value of my numeric ticker is changed. The ticker simply calls handle_resize() and does nothing else.
There's got to be a reason why it's doing this. It's like it's painting overtop of the other image. If I type in the values, then it works fine, but I can't consistently press the ticker.
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
|