imrankhanpathan


Hi friends

I have a bit problem.

I am working in asp.net 2.0 with c#.

In my application,I scan fingerprint of user from scanner and display it in Image control.

Now my problem is that I dont know that how to insert that image in sqldatabase as image datatype.

Here is another way.

I have one class called sfr and it has one method to get image of finger and it return in Bitmap format.

for this my code is here.

Bitmap Finger = sfr.GetLastImage();

System.Web.UI.WebControls.Image CandFinger=new System.Web.UI.WebControls.Image();

CandFinger =(System.Web.UI.WebControls.Image) Convert.ChangeType(Finger, typeof(System.Web.UI.WebControls.Image));

sfr is my class and getlastmethod is method that return scanned image of user.

Now I want to convert this image in Image object becouse of in my database I want to save this image in image datatype.

but last line of this code gives error that Object must implement IConvertible.

For this what I have to do

Can I insert Bitmap image as an Image datatype

Plz help me out and give me right solution.

Thanks in advance.




Re: convert Bitmap to Image

Raaja.K


Converting Bitmap to Image

Bitmap b = new Bitmap("asdf.jpg");
Image i = (Image)b;

We can't store the image directly to database. DB only accept byte array. So, we have to convert image to byte array before insert. See this line for byte array conversion.

Image to Byte array and Byte array to Image

I hope this will help you.








Re: convert Bitmap to Image

Nikolay Podkolzin

For Convert you may use it:

static public Bitmap BitmapFromBitmapData(byte[] BitmapData)

{

MemoryStream ms = new MemoryStream(BitmapData);

return (new Bitmap(ms));

}

static public byte[] BitmapDataFromBitmap(Bitmap objBitmap, ImageFormat imageFormat)

{

MemoryStream ms = new MemoryStream();

objBitmap.Save(ms, imageFormat);

return (ms.GetBuffer());

}