PocketSignature saved in the SQL CE database

  • Thread starter Thread starter SSP
  • Start date Start date
S

SSP

Any ideas on how, I can save the PocketSignature (sample on MSDN) into a SQL
CE database?

SSP
 
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.
 
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
 
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
 
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
 
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
 
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
 
How do you know they are the same? You cannot see a whole lot of data in SQL
CE Query

SSP said:
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 said:
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
Assembly.GetExecutingAssembly().GetManifestResourceStream("_signature.Signat
of
type into
 
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 said:
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 said:
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

portion
of
already
a
Assembly.GetExecutingAssembly().GetManifestResourceStream("DbAccess.River
Assembly.GetExecutingAssembly().GetManifestResourceStream("_signature.Signat
the
idea MSDN)
into
 
You cannot save the image as a gif file this way. It must have BMP extension

SSP said:
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 said:
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 said:
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

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


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
 
The bmp extension doesn't work either.

SSP

Alex Feinman said:
You cannot save the image as a gif file this way. It must have BMP extension

SSP said:
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 said:
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

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

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


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
for
an but
the
 
I guess I need to see the resulting file.

SSP said:
The bmp extension doesn't work either.

SSP

Alex Feinman said:
You cannot save the image as a gif file this way. It must have BMP extension

SSP said:
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

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

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

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


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
 
Back
Top