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

PocketSignature saved in the SQL CE database

173 views
Skip to first unread message

SSP

unread,
Feb 18, 2004, 7:49:42 PM2/18/04
to
Any ideas on how, I can save the PocketSignature (sample on MSDN) into a SQL
CE database?

SSP


Alex Feinman [MVP]

unread,
Feb 18, 2004, 8:05:20 PM2/18/04
to
IIRC they return a byte array. Byte array can be stored in a field of type
Image (SqlDbTypeImage)
See http://www.alexfeinman.com/download.asp?doc=DbAccess.zip for an example
of how to work with Image fields. The sample uses a bitmap, but the idea is
the same

"SSP" <s...@dt.com> wrote in message
news:%23Ky1RHo...@TK2MSFTNGP12.phx.gbl...

Yunwen Bai [MS]

unread,
Feb 18, 2004, 8:22:35 PM2/18/04
to
SQL CE supports image data type and the signiture can be saved as image
data to the SQLCE db. what you need to do is to read the file as bytes
stream and then use sqlce command with parameter to insert into to the db.

Regards!

Yunwen Bai
Sql Server CE

This posting is provided "AS IS" with no warranties, and confers no rights.

SSP

unread,
Feb 19, 2004, 2:53:24 AM2/19/04
to
Hi Alex,

That's a great example... I am however still puzzled over this portion of
the code:

In your code below, you are pointing to an image file which is already a
part of the project:
...................
Stream str =
Assembly.GetExecutingAssembly().GetManifestResourceStream("DbAccess.River
Sumida.bmp");
....................

In my app, I have the code as below, but when I debug, I get a Null Refence
error:
..................
Stream str =
Assembly.GetExecutingAssembly().GetManifestResourceStream("_signature.Signat
ureBits");
...................

What am I doing wrong?

SSP

"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message
news:uboIyRo...@TK2MSFTNGP11.phx.gbl...

SSP

unread,
Feb 19, 2004, 6:04:37 AM2/19/04
to
I know what the problem was for the below...Stream is an abstract class...

I now have another problem. When I tried to read the image from the database
I get a
................
An unhandled exception of type 'System.ArgumentException' occurred in
System.Drawing.dll
Additional information: ArgumentException
................
error

I have no problems reading from the the test database...just my production
database.

SSP


"SSP" <s...@dt.com> wrote in message

news:eCBnD0r...@TK2MSFTNGP10.phx.gbl...

SSP

unread,
Feb 19, 2004, 6:28:48 AM2/19/04
to
It's only the signature being read as image that gives this error.
If I insert an image file, I can read it fine. If it's the signature than,
then I get the ArgumentExecption error.

SSP

"SSP" <s...@dt.com> wrote in message

news:%232C55kt...@TK2MSFTNGP11.phx.gbl...

Alex Feinman [MVP]

unread,
Feb 19, 2004, 1:52:24 PM2/19/04
to
If you are passing a byte array to a bitmap constructor, this array is
expected to have a file format - as if you have read a valid image file into
memory. This could be any of the supported file formats, but for your needs
you will have to use bitmap file format. You cannot simply use the pixel
data part. The file is expected to have BITMAPFILEHEADER and BITMAPINFO
structures in the header part.

For an example of building these headers see
http://www.alexfeinman.com/download.asp?doc=OnTheFlyBitmap.zip
It in fact contains a ready-to-use function that creates a bitmap from cx,
cy and byte[] pixel data

"SSP" <s...@dt.com> wrote in message

news:ezbfrst9...@TK2MSFTNGP12.phx.gbl...

SSP

unread,
Feb 19, 2004, 7:42:21 AM2/19/04
to
Here's the "full" code

When I view the results of the sql query of the data entered, both "sig" and
"sig1", have the same data. This cannot be true, since they're both entered
from different paramaters i.e. _signature and _signature1

//The problem lies here.
Stream mstr;
Stream mstr1;
mstr = new MemoryStream(_signature.SignatureBits);
mstr1 = new MemoryStream(_signature1.SignatureBits);
byte [] sigData = new byte[mstr.Length];
byte [] sigData1 = new byte[mstr1.Length];

// Read it into byte array
mstr.Read(sigData, 0, (int)mstr.Length);
mstr1.Read(sigData1, 0, (int)mstr1.Length);

where am I going wrong?

SSP

"SSP" <s...@dt.com> wrote in message

news:%232C55kt...@TK2MSFTNGP11.phx.gbl...

Alex Feinman [MVP]

unread,
Feb 19, 2004, 5:52:29 PM2/19/04
to
How do you know they are the same? You cannot see a whole lot of data in SQL
CE Query

"SSP" <s...@dt.com> wrote in message

news:e2DGdmy9...@TK2MSFTNGP11.phx.gbl...

SSP

unread,
Mar 1, 2004, 10:03:54 PM3/1/04
to
Hi Alex,

I looked at both your examples and have tried to save the signature as an
image in the database, but it only saves a black image.

I am passing "_signature.SignatureBits" as the byte[]

---X----X----

int h = 120, w = 216;
byte [] datax = _signature.SignatureBits;
byte[] sigbitmap = CreateBitmap(w, h, datax);
MemoryStream ms = new MemoryStream(sigbitmap);
FileStream fs = new FileStream(@"\sigData.gif", FileMode.Create,
FileAccess.Write);
fs.Write(sigbitmap, 0, sigbitmap.Length);
fs.Close();
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = bmp;

---X----X----

I really need to be able to save the signature as an image or else...this
app is useless.

SSP

"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message

news:%23q0cEmx...@TK2MSFTNGP11.phx.gbl...

Alex Feinman [MVP]

unread,
Mar 2, 2004, 1:05:33 PM3/2/04
to
You cannot save the image as a gif file this way. It must have BMP extension

"SSP" <s...@dt.com> wrote in message

news:%23nk8NKA...@TK2MSFTNGP09.phx.gbl...

SSP

unread,
Mar 2, 2004, 6:59:40 PM3/2/04
to
The bmp extension doesn't work either.

SSP

"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message

news:OtG80DIA...@TK2MSFTNGP11.phx.gbl...

Alex Feinman [MVP]

unread,
Mar 5, 2004, 5:07:57 PM3/5/04
to
I guess I need to see the resulting file.

"SSP" <s...@dt.com> wrote in message

news:%23F9$6HLAEH...@TK2MSFTNGP11.phx.gbl...

0 new messages