Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > Graphics/GDI+

Graphics/GDI+ Graphics discussion for VB.NET applications, Winforms, Web, Compact Framework, etc.

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-17-2008, 5:04 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Oct 2008
Posts: 1
Reputation: 0
Rul3R is on a distinguished programming path ahead
Question How can i resize an image then save it into a database?

Hi!

I need to resize an image and then save it to the database.

In the line:
Code:
"Me.PictureBox1.Image.Save(ms,Me.PictureBox1.Image.RawFormat) "
Gets the error:
Quote:
"The valor canīt be null. Name of parameter: Encoder"
Can Somebody help me please?

The code is:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        With OpenFileDialog1
            .InitialDirectory = "C:\"
            .Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
            .FilterIndex = 2
        End With

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            With PictureBox1
                .Image = Image.FromFile(Me.OpenFileDialog1.FileName)
                .SizeMode = PictureBoxSizeMode.CenterImage
            End With

        End If
        
        Me.Label1.Text = Me.OpenFileDialog1.FileName.ToString

        Dim ms As New MemoryStream

       Dim width As Integer = 100

        Dim height As Integer = 100

        PictureBox1.Image = PictureBox1.Image.GetThumbnailImage(width, height, Nothing, Nothing)

        Me.PictureBox1.Image.Save(ms, Me.PictureBox1.Image.RawFormat)

        Dim arrayImage() As Byte = ms.GetBuffer

        ms.Close()

        Dim nStr As String = Me.Label1.Text.Substring(Me.Label1.Text.LastIndexOf("\") + 1)

        Dim strQuery As String = "INSERT INTO Imagens(NomeImagem, Imagem) VALUES(@NomeImagem, @Imagem)"

        Dim objcommand As New SqlCommand(strQuery, Me.SqlConnection1)
        With objcommand
            .Parameters.Add(New SqlParameter("@NomeImagem", SqlDbType.NVarChar, 50)).Value = nStr
            .Parameters.Add(New SqlParameter("@Imagem", SqlDbType.Image)).Value = arrayImage
        End With

        Me.SqlConnection1.Open()
        objcommand.ExecuteNonQuery()
        Me.SqlConnection1.Close()

        Me.SqlConnection1.Open()

        Me.DataSet11.Clear()
        Me.SqlDataAdapter1.Fill(Me.DataSet11.Imagens)

        With Me.ListBox1
            .DataSource = Me.DataSet11.Imagens
            .DisplayMember = "NomeImagem"

        End With

        Me.SqlConnection1.Close()
Thank you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 5:15 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.