Fórum COMO MOSTRAR IMAGEM SALVA NO MSQL SERVER #15619
12/02/2010
0
MainForm.conn.Open ();
SqlCommand cmd=new SqlCommand ("Select picture from images where picname like '"+image+"';",MainForm.conn);
byte [] content = (byte[] )cmd.ExecuteScalar();
try
{
MemoryStream stream = new MemoryStream(content);
pic1.Image= Image.FromStream(stream);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString ());
Sidney Mendonça/
Curtir tópico
+ 0Posts
12/02/2010
Luiz Maia
c.Open();
SqlCommand k = new SqlCommand(“SELECT BINARIO FROM IMAGENS WHERE NOME = @NOME”, c);
k.Parameters.Add(“@NOME”, SqlDbType.VarChar, 50);
k.Parameters[“@NOME”].Value = comboBox1.Text;
byte[] imagemEmBytes = (byte[])k.ExecuteScalar();
MemoryStream ms = new MemoryStream();
ms.Write(imagemEmBytes, 0, imagemEmBytes.Length);
pictureBox1.Image = Image.FromStream(ms); Aguardo seu retorno. Abraços Att Luiz Maia
Gostei + 0
12/02/2010
Sidney Mendonça/
Gostei + 0
18/02/2010
Luiz Maia
SqlCommand myCommand = new SqlCommand(SQL, Conn); myCommand.Parameters.AddWithValue("@id", imagemID); Conn.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read()) { Response.ContentType = myReader["MIME"].ToString(); Response.BinaryWrite((byte[])myReader["imagem"]); } myReader.Close(); Conn.Close(); } } catch (Exception ex) { Response.Write(ex.ToString()); } } Aguardo seu retorno caso tenha alguma dificuldade. Abraços Att Luiz Maia
Gostei + 0
18/02/2010
Sidney Mendonça/
Gostei + 0
18/02/2010
Luiz Maia
Gostei + 0
18/02/2010
Sidney Mendonça/
1) O que devo passar como parâmetro (no string path) da loadResource?
2) Como atribuir o retorno ao Control image do webform. Grato
Gostei + 0
19/02/2010
Luiz Maia
Gostei + 0
23/02/2010
Sidney Mendonça/
Gostei + 0
23/02/2010
Luiz Maia
Cole o codigo abaixo:
if (Request.QueryString["Id"] != null)
{
int Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
byte[] image = null;
//You will have to add your connection information and grab the image from the database
// ToDo: Load binary image into image variable;
if (image!=null)
{
MemoryStream ms = new MemoryStream(image);
Bitmap b = new Bitmap(Image.FromStream(ms));
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
}
else
{
Bitmap b = new Bitmap(Image.FromFile(Server.MapPath("images/noimage.png")));
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
}
}
else
{
Bitmap b = new Bitmap(Image.FromFile(Server.MapPath("images/noimage.png")));
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
}Na pagina que vc quer dar o bind na imagem, altere o ImageUrl seguindo a instrução abaixo:
Image1.ImageUrl = "LoadImage.aspx?Id=1";
Aguardo retorno.AttLuiz Maia
Gostei + 0
23/02/2010
Sidney Mendonça/
Gostei + 0
23/02/2010
Sidney Mendonça/
Gostei + 0
23/02/2010
Sidney Mendonça/
Gostei + 0
23/02/2010
Sidney Mendonça/
Gostei + 0
23/02/2010
Sidney Mendonça/
Gostei + 0
23/02/2010
Sidney Mendonça/
Image1.ImageUrl = "LoadImage.aspx?Id=1"; Por isso que eu não estava entendendo. Vou testar e darei retorno. Grato Sidney
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)