Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Control to load a JPG file - Binary stream

Hi,

is there any control which can load a jpg file by passing the Binary stream.


pls let me know asap.
thanks.
0
chandua
Asked:
chandua
  • 2
  • 2
1 Solution
 
_TAD_Commented:


No, but you can load an image object from a stream and then drop that Image onto a picturebox.


it will look something like this:

picturebox1.Image = Image.FromStream(myBinaryStream);
0
 
chanduaAuthor Commented:
hi TAD,

i am creating a Webpart (SPS 2003), i cant have a picture box in it.
0
 
chanduaAuthor Commented:
hi TAD,

i am trying to get the stream from database
string sqlText = "SELECT img_data FROM Image WHERE img_pk = " + ImageId;
SqlConnection connection = new SqlConnection( ConfigurationSettings.AppSettings["DSN"].ToString() );
SqlCommand command = new SqlCommand( sqlText, connection);
 //open the database and get a datareader
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if ( dr.Read()) //found image
{
 pictureBox1.Image=Image.FromStream((byte[]) dr["img_data"]);
}
i cant pass the dr["img_data"].. how do i convert to straeam/
0
 
_TAD_Commented:


Create a Memory Stream.


MemoryStream memStr = new MemoryStream(myByteArray);
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now