GFX010 0 Newbie Poster

Greetings to all,

I have two functions:

Function 1: ImageToByteArray: Is used to Convert an Image into a Byte Array and then Store in an Oracle Database, in a BLOB Field.

            public byte[] ImageToByteArray(string sPath)
            {
                byte[] data = null;
                FileInfo fInfo = new FileInfo(sPath);
                long numBytes = fInfo.Length;
                FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fStream);
                data = br.ReadBytes((int)numBytes);
                return data;
            }

Function 2: ByteArrayToImage: Is used to Convert a Byte Array from the Database into an Image:

           public System.Drawing.Image ByteArrayToImage(byte[] byteArray)
            {
                MemoryStream img = new MemoryStream(byteArray);
                System.Drawing.Image returnImage = System.Drawing.Image.FromStream(img);
                return returnImage;
            }

In my Markup I have an Imgage Control:
<asp:Image ID="Image1" runat="server" />

In the Code Behind I want to Assign the Returned Value from Function 2 to (which is of type System.Drawing.Image) to the "image1" control which is of type (System.Web.UI.WebControls.Image).

Obviously I can't just assign:
image1 = ByteArrayToImage(byteArray);
because I'd get the following error: Cannot implicitly convert type 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'

Is there anyway to do this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.