Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Save Ink to image or database (MS SQL)

64 views
Skip to first unread message

Fabio Reynoso

unread,
Jun 23, 2006, 4:10:42 PM6/23/06
to
Hi all.

I'd like to be able to save Ink (from Ink enabled applications) to an image
or a MS SQL Server Database. I already made work the ink, but don't know
how to save it.

Thanks for any advise.

Regards,

Fabio Reynoso


Wayne Niddery [TeamB]

unread,
Jun 23, 2006, 7:10:53 PM6/23/06
to
Fabio Reynoso wrote:
>
> I'd like to be able to save Ink (from Ink enabled applications) to an
> image or a MS SQL Server Database. I already made work the ink, but
> don't know how to save it.

What form are you holding the ink data? I would assume a stream, or at least
you can save it to (memory) stream. If so then you can get it to the
database using a parameterized Insert statement (the field in the database
should be an appropriate blob type).

E.g: setting the SQL of the dataset component to:
insert into mytable (fld1, fld2, inkfield) values (:fld1, :fld2,
:inkfield);
You can now assign the parameters of the dataset. The parameter for inkfield
should be a blob field with methods to read from the stream.

--
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"Some see private enterprise as a predatory target to be shot, others
as a cow to be milked, but few are those who see it as a sturdy horse
pulling the wagon." - Winston Churchill


Fabio Reynoso

unread,
Jun 24, 2006, 2:37:00 PM6/24/06
to
Thanks Wayne for you help.

Right now I'm not hold or saving the ink.

Here's an example written in C# which I've tried to recreate in Delphi, but
I guess I'm missing something because it doesn't work for me.

private void button3_Click(object sender, System.EventArgs e)
{
FileStream fs = new FileStream(@"..\myink.gif",FileMode.Create);
byte[] inkBytes = inkOverlay.Ink.Save(PersistenceFormat.Gif);
fs.Write(inkBytes, 0, inkBytes.Length);
fs.Close();
}

This example saves the ink to an image (gif file).

The following one saves it to a MS SQL Server Database Table, but I can't
get it to in Delphi (of course trying to replicate it with delphi code).

Private Sub btnSaveDB_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles btnSaveDB.Click

' The SQL Server Image datatype is a binary datatype.
' To save it to the database we must convert the ink
' to an array of bytes. We will use
' MemoryStream with the inkCollector.Ink.Save method.
Dim Filename As String
Dim isf As Byte()

If inkEdFileName.Text.Length = 0 Then
MessageBox.Show("You must enter a file name.", _
"Missing File Name", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Else
' Perform the serialization
isf = myInkCollector.Ink.Save _
(PersistenceFormat.InkSerializedFormat)

'append the .ink extension to denote .INK data
inkEdFileName.Text = _
Trim(inkEdFileName.Text) & ".ink"
Filename = inkEdFileName.Text

Dim isConnecting As Boolean = True
While isConnecting
Try
Dim northwindConnection As _
New SqlConnection(connectionString)
Dim strSQL As String = _
"INSERT INTO Picture (Filename, Picture)" & _
"VALUES (@Filename, @Picture)"

myCmd = New SqlCommand(strSQL, _
northwindConnection)

With myCmd
' Add parameters required by SQL
' statement.
'PictureID is an
' identity field so only pass values for
'the two remaining fields.
.Parameters.Add(New SqlParameter _
("@Filename", _
SqlDbType.NVarChar, 50)).Value _
= Filename

.Parameters.Add(New SqlParameter_
("@Picture", SqlDbType.Image)).Value _
= isf
End With

' Open the connection, execute the command,
'and close the connection.
northwindConnection.Open()
myCmd.ExecuteNonQuery()
northwindConnection.Close()

' Data has been successfully submitted,
'so break out of the loop
isConnecting = False

MessageBox.Show(Filename & _
" saved to the " & _
"database.", _
"Ink Save Status", MessageBoxButtons.OK, _
MessageBoxIcon.Information)

Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString, _
"SQL Exception Error!", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit While
Catch exc As Exception
' Unable to connect to SQL Server
MessageBox.Show("Error connecting " & _
"to Database.", _
"Connection Failed!", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
End While
End If
End Sub

Maybe I'm asking too much, I'd really appreciate some help.

Thanks again.

Regards,

Fabio.

"Wayne Niddery [TeamB]" <wnid...@chaffaci.on.ca> wrote in message
news:449c74fd$1...@newsgroups.borland.com...

Wayne Niddery [TeamB]

unread,
Jun 24, 2006, 2:58:17 PM6/24/06
to
Fabio Reynoso wrote:
>
> Here's an example written in C# which I've tried to recreate in
> Delphi, but I guess I'm missing something because it doesn't work for
> me.
> private void button3_Click(object sender, System.EventArgs e)
> {
> FileStream fs = new FileStream(@"..\myink.gif",FileMode.Create);
> byte[] inkBytes = inkOverlay.Ink.Save(PersistenceFormat.Gif);
> fs.Write(inkBytes, 0, inkBytes.Length);
> fs.Close();
> }

The VB example quoted below this seems to be far more complicated than it
needs to be. I would change it to be more like the C# code above, but save
it to a memory stream instead of a file stream. Then you should be able to
write that stream to the @Picture parameter of the query. It's difficult to
give you exact code at the moment, perhaps someone else can jump in.

--
Wayne Niddery - Winwright, Inc (www.winwright.ca)

"Those who disdain wealth as a worthy goal for an individual or a
society seem not to realize that wealth is the only thing that can
prevent poverty." - Thomas Sowell


Fabio Reynoso

unread,
Jun 24, 2006, 8:12:13 PM6/24/06
to
Thanks anyway Wayne.

I'm working on figuring out how to translate this code from VB or C# and
make it work.

Thanks you so much.

Regards.

Fabio.

"Wayne Niddery [TeamB]" <wnid...@chaffaci.on.ca> wrote in message

news:449d8b49$1...@newsgroups.borland.com...

0 new messages