Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing Images in VB.NET

I'd like to make a simple VB utility to resize images using vb.net. I am having trouble figuring out what vb class to use to actually manipulate the images. The Image class and the Bitmap class don't work.

Any ideas, hints, tips, tutorial links are greatly appreciated.

Thanks.

like image 864
Moshe Avatar asked Jan 27 '10 04:01

Moshe


2 Answers

You can simply use this one line code to resize your image in visual basic .net

Public Shared Function ResizeImage(ByVal InputImage As Image) As Image
        Return New Bitmap(InputImage, New Size(64, 64))
End Function

Where;

  1. "InputImage" is the image you want to resize.
  2. "64 X 64" is the required size you may change it as your needs i.e 32X32 etc.
like image 71
Muhammad Saqib Avatar answered Sep 30 '22 20:09

Muhammad Saqib


Here is an article with full details on how to do this.

Private Sub btnScale_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnScale.Click
    ' Get the scale factor.
    Dim scale_factor As Single = Single.Parse(txtScale.Text)

    ' Get the source bitmap.
    Dim bm_source As New Bitmap(picSource.Image)

    ' 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)

    ' Copy the source image into the destination bitmap.
    gr_dest.DrawImage(bm_source, 0, 0, _
        bm_dest.Width + 1, _
        bm_dest.Height + 1)

    ' Display the result.
    picDest.Image = bm_dest
End Sub

[Edit]
One more on the similar lines.

like image 42
Binoj Antony Avatar answered Sep 30 '22 19:09

Binoj Antony