Northwind Image fields

Posts   
 
    
he00273
User
Posts: 133
Joined: 02-Oct-2008
# Posted on: 18-Aug-2009 11:06:39   

I am looking at blobs in SQL Server.

Just to start with I am getting a single northwind employee entity.

I want to be able to use the image in the entity and use this with a standard PictureBox control.

I have tried this

  private void button1_Click(object sender, EventArgs e)
    {
        EmployeeEntity ThisChap = new EmployeeEntity(2);

        pictureBox1.Image = byteArrayToImage(ThisChap.Photo);
    }

    public Image byteArrayToImage(byte[] byteArrayIn)
    {
        MemoryStream ms = new MemoryStream(byteArrayIn);
        Image returnImage = Image.FromStream(ms);
        return returnImage;
    }

I get this exception frowning

System.ArgumentException was unhandled Message="Parameter is not valid." Source="System.Drawing"

Ok I know that the images stored in Northwind are pretty crap but I thought I would get further than this.cry

There is not much for handling blobs on your site. Most of what I found was how to exclude them in a fetch.disappointed

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 18-Aug-2009 11:31:02   

Please check the ASP.NET 2.0 databinding example not the CRUD one. http://www.llblgen.com/pages/secure/ListDownloads.aspx?ProductVersion=6

It's using the same database to display employee information along with their images.

he00273
User
Posts: 133
Joined: 02-Oct-2008
# Posted on: 19-Aug-2009 03:16:43   

Thanks Walaa

I removed the OleHeader bytes and it works and displays really crap images now. sunglasses (one would think they could have done better with the images) confused

As others viewed this and as your example used Response.BinaryWrite(strippedImageData);

my code for winforms is

   private void button1_Click(object sender, EventArgs e)
    {
        EmployeeEntity ThisChap = new EmployeeEntity(2);

        pictureBox1.Image = byteArrayToImage(ThisChap.Photo);
    }

    public Image byteArrayToImage(byte[] byteArrayIn)
    {
        return byteArrayToImage(byteArrayIn,true);
    }

    public Image byteArrayToImage(byte[] byteArrayIn, bool stripOleHeader)
    {
        int strippedImageLength = byteArrayIn.Length - (stripOleHeader ? 78 : 0);
        byte[] strippedImageData = new byte[strippedImageLength];
        Array.Copy(byteArrayIn, (stripOleHeader ? 78 : 0), strippedImageData, 0, strippedImageLength);
        MemoryStream ms = new MemoryStream(strippedImageData);
        return Image.FromStream(ms);
    }

All cool now smile