Click here to Skip to main content
16,013,465 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code in vb. i want to zoom an image

What I have tried:

VB
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

      Dim scale_factor As Single = Single.Parse(txtScale.Text)  
       ' Get the source bitmap.

      Dim bm_source As New Bitmap(originalimage)

            ' Make a bitmap for the result.
            Dim bm_dest As New Bitmap( _
                CInt(bm_source.Width * scale_factor), _
                CInt(bm_source.Height * scale_factor))

            ' Make a Graphics object for the result Bitmap.
            Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)

            gr_dest.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

            'display the result
            picturebox1.Image = New Bitmap(bm_dest)
    end sub


but when i run the code it throws thise exception


Unhandled System.ArgumentException.. Additional Information: Parameter is not valid
Posted
Updated 27-Nov-16 10:06am
v2
Comments
Wendelius 27-Nov-16 13:16pm    
On what line the exception is thrown?
Sharma Hussein 27-Nov-16 13:21pm    
here
Dim bm_dest As New Bitmap( _
CInt(bm_source.Width * scale_factor), _
CInt(bm_source.Height * scale_factor))

Looking at the line
C#
Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)

You try to create a graphics object from an empty image you have just created on the previous line. Is this intentional or should it be
C#
Dim gr_dest As Graphics = Graphics.FromImage(bm_source)


[ADDED]
Since the exception is in creation of the bitmap, ensure that the result of the multiplication is feasible. For example, could it be that the scale_factor is 0.
 
Share this answer
 
v2
Comments
Wendelius 27-Nov-16 13:30pm    
See the updated answer.
Bitmaps use unmanaged resources and that led to memory pressure issues. I Wrapped bm_source with a Using statement blocks and that seems to have fixed it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900