Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have a drawing program on frmdraw. I want to save the what the user draws to the database I guess saving it as a bitmap. Do I just put a picturebox on my form to draw on. If so do I cut and paste my code in the picture box object?
  • Administrators
Posted

Not too sure what you mean by

I have a drawing program on frmdraw
.

Have you written this drawing program yourself or is it a 3rd party component you are using?

If you are drawing to a picturebox then you should be able to use code like

picturebox1.image.Save(...)

 

also not sure what you meant by

do I cut and paste my code in the picture box object?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Its a drawing program that I copied out of a book. When the user types in a value into my textbox and clicks on the command button the draw form pops up. The user than can draw on the form. I need to be able to save the image in my database so when the user runs the program again, they can select the that value from a combobox and the image will display. :)
Posted

sorry about that. In this form I have a program that will draw on the the form when ran. I need to save the image in my sql database. I have a menu at the top right hand corner that has a submenu called save. here is my code.

 

Imports System.Drawing

Imports System.Drawing.Drawing2D

Public Class frmdraw

Inherits System.Windows.Forms.Form

 

' enums....

Public Enum GraphicsTools As Integer

CirclePen = 0

End Enum

Public Enum GraphicsSizes As Integer

Small = 4

Medium = 10

Large = 20

End Enum

' members.....

Public GraphicsItem As New ArrayList

Public GraphicTool As GraphicsTools = GraphicsTools.CirclePen

Public GraphicsSize As GraphicsSizes = GraphicsSizes.Large

Public GraphicColor As Color = Color.Black

' DoMousePaint - respond to a mouse movement....

Private Sub DoMousePaint(ByVal e As MouseEventArgs)

' store the new item somewhere...

Dim newItem As GraphicsItem

' what tool are you using?

Select Case GraphicTool

' circlepen?

Case GraphicTool.CirclePen

' create a new graphics circle...

Dim circle As New GraphicsCircle

circle.SetPoint(e.X, e.Y, GraphicsSize, GraphicColor, True)

' store this for addition...

newItem = circle

End Select

' where you given an item?

If Not newItem Is Nothing Then

' add it to the list...

GraphicsItem.Add(newItem)

'invalidate...

Invalidate()

 

End If

 

End Sub

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

 

' is the button down?

If e.Button = MouseButtons.Left Then

DoMousePaint(e)

End If

 

 

 

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

' is the button down?

If e.Button = MouseButtons.Left Then

DoMousePaint(e)

End If

End Sub

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

' go through the list...

Dim item As GraphicsItem

For Each item In GraphicsItem

'ask each item to draw itself

item.Draw(e.Graphics)

Next

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''this is my save menu''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 

 

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click

Dim bmp As New Bitmap(300, 300)

Dim bmpRect As New Rectangle(0, 0, bmp.Width, bmp.Height)

Dim g As Graphics = Graphics.FromImage(bmp)

g.SmoothingMode = SmoothingMode.HighQuality

 

g.FillRectangle(New Drawing2D.LinearGradientBrush(bmpRect, Color.White, Color.SlateGray, 50), bmpRect)

 

Dim x, y As Double

For degree As Integer = 0 To 359 Step 15

x = Math.Sin((degree / 180) * Math.PI) * 35 + bmp.Width / 2

y = Math.Cos((degree / 180) * Math.PI) * 35 + bmp.Height / 2

 

g.DrawEllipse(Pens.Black, New RectangleF(CSng(x) - 50, CSng(y) - 50, 100, 100))

Next

g.DrawString("created by GDI+ & VB.NET", Font, Brushes.Black, 2, 2)

g.DrawRectangle(Pens.Red, 0, 0, bmp.Width - 1, bmp.Height - 1)

 

g.Dispose()

 

Dim memStrm As New IO.MemoryStream

 

bmp.Save(memStrm, Imaging.ImageFormat.Jpeg)

bmp.Dispose()

 

Dim buffer() As Byte = memStrm.ToArray()

'do something to insert this byte-buffer in to a

'Bit(Byte?)Array-column (I guess that shoud be the right type) of a new DataRow...

 

'just for testing: save the file to disk:

Dim fs As IO.FileStream = IO.File.Create("test.jpg")

fs.Write(buffer, 0, buffer.Length)

fs.Flush()

fs.Close()

End Sub

End Class

 

 

where do i go from here????????????????

Posted

This is my first time with buffers. Can you show me how I FILL the buffer?

 

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click

Dim bmp As New Bitmap(300, 300)

Dim bmpRect As New Rectangle(0, 0, bmp.Width, bmp.Height)

Dim g As Graphics = Graphics.FromImage(bmp)

g.SmoothingMode = SmoothingMode.HighQuality

 

g.FillRectangle(New Drawing2D.LinearGradientBrush(bmpRect, Color.White, Color.SlateGray, 50), bmpRect)

 

Dim x, y As Double

For degree As Integer = 0 To 359 Step 15

x = Math.Sin((degree / 180) * Math.PI) * 35 + bmp.Width / 2

y = Math.Cos((degree / 180) * Math.PI) * 35 + bmp.Height / 2

 

g.DrawEllipse(Pens.Black, New RectangleF(CSng(x) - 50, CSng(y) - 50, 100, 100))

Next

g.DrawString("created by GDI+ & VB.NET", Font, Brushes.Black, 2, 2)

g.DrawRectangle(Pens.Red, 0, 0, bmp.Width - 1, bmp.Height - 1)

 

 

Dim memStrm As New IO.MemoryStream

 

bmp.Save(memStrm, Imaging.ImageFormat.Jpeg)

' create buffer to hold data

Dim buffer() As Byte = memStrm.ToArray()

 

' connect to the database

Dim SQLConn As SqlConnection = New SqlConnection

Dim strSQl As String = strSQl = "INSERT INTO [Auto] (ItemImage) VALUES (@MyImage)"

 

 

SQLConn.ConnectionString = "Data Source=(local);" & _

"Initial Catalog=Justin;" & _

"Integrated Security=SSPI"

 

 

Dim MyCommand As New SqlCommand

MyCommand.CommandText = strSQl

MyCommand.Connection = SQLConn

 

SQLConn.Open()

' Construct INSERT Command

 

 

MyCommand.Parameters.Add("@MyImage", SqlDbType.Image, buffer.Length).Value = buffer

 

MyCommand.ExecuteNonQuery()

 

SQLConn.Close()

bmp.Dispose()

End Sub

 

 

End Class

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...