عندى PictureBox1 عند اختيار لون من شاشة الالوان يت ادراجه الى PictureBox1 ولكن عند الحفظ يعطى خطا فالمطلوب حفظ PictureBox1 على انها صورة تحتوى على اللون الذى تم اختياره ولكنها لا تحفظ لان البرنامج يرى انه لايوجد صورة لحفظا فما الحل
ارفقت الاكواد وكود الحفظ
Using Image As System.Drawing.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.DrawToBitmap(Image, Me.PictureBox1.ClientRectangle)
Image.Save(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "NewImageTest.jpg"))
End Using
03-10-22, 07:27 PM (آخر تعديل لهذه المشاركة : 03-10-22, 07:29 PM {2} بواسطة Lathe1.)
(03-10-22, 06:43 PM)عبدالله الدوسري كتب :
كود :
Using Image As System.Drawing.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.DrawToBitmap(Image, Me.PictureBox1.ClientRectangle)
Image.Save(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "NewImageTest.jpg"))
End Using
اشكرك اخى العزيز ولكن كيف اضيف الصورة الى قاعدة بيانات sql server
(03-10-22, 06:43 PM)عبدالله الدوسري كتب :
كود :
Using Image As System.Drawing.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.DrawToBitmap(Image, Me.PictureBox1.ClientRectangle)
Image.Save(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "NewImageTest.jpg"))
End Using
Public Sub Insert_clore_(ByVal id As Int32, ByVal nam_ As String, ByVal col_ As PictureBox)
Try
If (Con.State And System.Data.ConnectionState.Broken = System.Data.ConnectionState.Broken) Then
Con.Close()
End If
If (Con.State = Global.System.Data.ConnectionState.Closed) Then
Con.Open
End If
Using Cmd As New System.Data.SqlClient.SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into clore_ ( id,nam_,col_)values(@id,@nam_,@col_)"
.Parameters.Clear()
.Parameters.AddWithValue("@id", SqlDbType.Int).Value = id
.Parameters.AddWithValue("@nam_", SqlDbType.VarChar).Value = nam_
Dim p As New System.Data.SqlClient.SqlParameter("@col_", SqlDbType.Image)
Using MS As New System.IO.MemoryStream()
Using bmpImage As System.Drawing.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.DrawToBitmap(bmpImage, Me.PictureBox1.ClientRectangle)
bmpImage.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg)
p.Value = MS.GetBuffer()
End Using
.Parameters.Add(p)
If .ExecuteNonQuery() > 0 Then
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
Else
MsgBox("لم يتم إضافة السجل لسبب غير معروف", MsgBoxStyle.Information, "حفظ")
End If
End Using
End With
End Using
Catch ex As Exception
MsgBox(ex.Message)
Finally
Con.Close()
End Try
End Sub
Public Sub Insert_clore_(ByVal id As Int32, ByVal nam_ As String, ByVal col_ As PictureBox)
Try
If (Con.State And System.Data.ConnectionState.Broken = System.Data.ConnectionState.Broken) Then
Con.Close()
End If
If (Con.State = Global.System.Data.ConnectionState.Closed) Then
Con.Open
End If
Using Cmd As New System.Data.SqlClient.SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into clore_ ( id,nam_,col_)values(@id,@nam_,@col_)"
.Parameters.Clear()
.Parameters.AddWithValue("@id", SqlDbType.Int).Value = id
.Parameters.AddWithValue("@nam_", SqlDbType.VarChar).Value = nam_
Dim p As New System.Data.SqlClient.SqlParameter("@col_", SqlDbType.Image)
Using MS As New System.IO.MemoryStream()
Using bmpImage As System.Drawing.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.DrawToBitmap(bmpImage, Me.PictureBox1.ClientRectangle)
bmpImage.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg)
p.Value = MS.GetBuffer()
End Using
.Parameters.Add(p)
If .ExecuteNonQuery() > 0 Then
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
Else
MsgBox("لم يتم إضافة السجل لسبب غير معروف", MsgBoxStyle.Information, "حفظ")
End If
End Using
End With
End Using
Catch ex As Exception
MsgBox(ex.Message)
Finally
Con.Close()
End Try
End Sub
السلام عليكم لقد قمت بارفاق كود للرسم على picturbox ونجحت فى ذلك ولكن عند الحفظ استخدمت نفس الكود السابق يحفظ ولكن صورة فارغة ما الحل