CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2016
    Posts
    2

    How to crop and resize image using vb.net and SQL Server

    I'm using vb.net and sql server 2008 and a picturebox for uploading photos. This is what I want to do.

    1.The image can be anything. It can be bitmap,jpg,png, anything 2. upload image from my computer 3. Crop the image and resize it to fit in my picture box. 4. Save it to the SQL Server database

    This is my working code for uploading and saving images in the database.

    Code:
    Public Class Form1
      Dim a As New OpenFileDialog
    
     Private Sub PictureBox1_DoubleClick(sender As Object, e As EventArgs) Handles PictureBox1.DoubleClick
            Dim picl as string
            a.filter = nothing
            picl = a.filename
            a.showdialog()
            picturebox1.image = image.fromfile(a.filename)
     End Sub
    
     Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
     cn.Open()
        Using cmd As New SqlClient.SqlCommand("dbo.uspAdd", cn)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.Add(New SqlClient.SqlParameter("@customerPic", SqlDbType.Image)).Value = IO.File.ReadAllBytes(a.FileName)
                    cmd.ExecuteNonQuery()
                    MsgBox("Save Record New record Successfully")
                End Using
    cn.close
    End Sub
    This is what i have tried and now i'm stuck for almost an hour.

    Code:
    Imports System.Drawing.Drawing2D
        Public Class Form1
        Dim a As New OpenFileDialog
        Private Sub PictureBox1_DoubleClick(sender As Object, e As EventArgs) Handles PictureBox1.DoubleClick
            Dim picl As String
            a.Filter = Nothing
            picl = a.FileName
            a.ShowDialog()
            PictureBox1.Image = Image.FromFile(a.FileName)
            Dim OriginalImage = Image.FromFile(a.FileName)
            Dim CropRect As New Rectangle(100, 0, 100, 100)
            Dim CropImage = New Bitmap(CropRect.Width, CropRect.Height)
            Using grp = Graphics.FromImage(CropImage)
                grp.DrawImage(OriginalImage, New Rectangle(0, 0, CropRect.Width, CropRect.Height), CropRect, GraphicsUnit.Pixel)
                OriginalImage.Dispose()
            End Using
        End Sub
    Can someone please help me to fix my code. Any help would be very much appreciated. Thanks

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How to crop and resize image using vb.net and SQL Server

    So what problem are you actually having. What does that code you have tried do vs what you want it to do?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to crop and resize image using vb.net and SQL Server

    For image ma nipulation, these articles will be helpful:

    Creating Your Own Drawing Application with Visual Basic .NET, Part 1
    http://www.codeguru.com/csharp/.net/...le.php/c13205/

    Creating Your Own Drawing Application with Visual Basic.NET, Part 2
    http://www.codeguru.com/csharp/.net/...le.php/c13207/

    Creating Your Own Drawing Application in Visual Basic.NET, Part 3
    http://www.codeguru.com/vb/gen/vb_gr...le.php/c13611/

    Creating Your Own Drawing Application in Visual Basic.NET, Part 4
    http://www.codeguru.com/vb/gen/vb_gr...cle.php/c14007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured