Hi,

I am trying to load images stored in database (SQL CE) inside a grid but
facing problems on how to go about the same.

I am trying to use the Image class but do not find a method to read the
MemoryStream to get images.

Please suggest.

Regards,
Arjun

RE: Load images from database by dbgrick

dbgrick
Thu Jun 14 09:51:05 CDT 2007

Arjun,
Use the Bitmap class instead of the image class. You can create a bitmap
using a memory stream, which you can create from you database byte stream.

Rick D.
Contractor

"Arjun" wrote:

> Hi,
>
> I am trying to load images stored in database (SQL CE) inside a grid but
> facing problems on how to go about the same.
>
> I am trying to use the Image class but do not find a method to read the
> MemoryStream to get images.
>
> Please suggest.
>
> Regards,
> Arjun

RE: Load images from database by Arjun

Arjun
Thu Jun 14 11:28:01 CDT 2007

Hi rick,

Thanx for the suggestion. While trying to sue the Butmap class, I ma still
facing some issues.

below is the code I am using:
================
Bitmap loadimage(byte[] picdata)
{
const int bmData = 78;
if (picData == null || picData.Length < bmData + 2) return null;
if (picData[0] != 0x15 || picData[1] != 0x1c) return null;
Bitmap bmp = null;
try
{
MemoryStream ms = new MemoryStream(picData.Length - bmData);

bmp = new Bitmap(ms);
}
catch { }

// return what we got
return bmp;
}
===========================

but this is giving errors while building that picdatadoes not exists.

Please suggest.

Thanx again for your help.

Regards,
Arjun



"dbgrick" wrote:

> Arjun,
> Use the Bitmap class instead of the image class. You can create a bitmap
> using a memory stream, which you can create from you database byte stream.
>
> Rick D.
> Contractor
>
> "Arjun" wrote:
>
> > Hi,
> >
> > I am trying to load images stored in database (SQL CE) inside a grid but
> > facing problems on how to go about the same.
> >
> > I am trying to use the Image class but do not find a method to read the
> > MemoryStream to get images.
> >
> > Please suggest.
> >
> > Regards,
> > Arjun

RE: Load images from database by Arjun

Arjun
Thu Jun 14 11:54:02 CDT 2007

Hi Rick,

I ahve fixed the error mentioend int he previous mail. However the image is
still not being displayed. It just shows System.Byte[].

Any help on this would be highly appreciated.

regards,
Arjun

"dbgrick" wrote:

> Arjun,
> Use the Bitmap class instead of the image class. You can create a bitmap
> using a memory stream, which you can create from you database byte stream.
>
> Rick D.
> Contractor
>
> "Arjun" wrote:
>
> > Hi,
> >
> > I am trying to load images stored in database (SQL CE) inside a grid but
> > facing problems on how to go about the same.
> >
> > I am trying to use the Image class but do not find a method to read the
> > MemoryStream to get images.
> >
> > Please suggest.
> >
> > Regards,
> > Arjun

RE: Load images from database by dbgrick

dbgrick
Fri Jun 15 09:12:00 CDT 2007

Your memory stream should be constructed from your image data


byte[] picData;

MemoryStream ms = new MemoryStream(picData);
Bitmap bm = new Bitmap(ms);

As long as your image data is valid, this should work.

Rick D.
Contractor

"Arjun" wrote:

> Hi Rick,
>
> I ahve fixed the error mentioend int he previous mail. However the image is
> still not being displayed. It just shows System.Byte[].
>
> Any help on this would be highly appreciated.
>
> regards,
> Arjun
>
> "dbgrick" wrote:
>
> > Arjun,
> > Use the Bitmap class instead of the image class. You can create a bitmap
> > using a memory stream, which you can create from you database byte stream.
> >
> > Rick D.
> > Contractor
> >
> > "Arjun" wrote:
> >
> > > Hi,
> > >
> > > I am trying to load images stored in database (SQL CE) inside a grid but
> > > facing problems on how to go about the same.
> > >
> > > I am trying to use the Image class but do not find a method to read the
> > > MemoryStream to get images.
> > >
> > > Please suggest.
> > >
> > > Regards,
> > > Arjun