 |
|
VB.NET สอบถามวิธีการดึงรูปภาพที่บันทึกไว้(เป็น Binary data)ในฐานข้อมูลเอามาแสดงใน PictureBox ครับ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
connection.Open();
SqlCommand command1 = new SqlCommand("select imgfile from myimages where imgname=@param", connection);
SqlParameter myparam = command1.Parameters.Add("@param", SqlDbType.NVarChar, 30);
myparam.Value = txtimgname.Text;
byte[] img = (byte[])command1.ExecuteScalar();
MemoryStream str = new MemoryStream();
str.Write(img, 0, img.Length);
Bitmap bit = new Bitmap(str);
Response.ContentType = "image/jpeg";
bit.Save(Response.OutputStream, ImageFormat.Jpeg);
connection.Close();
|
 |
 |
 |
 |
Date :
2010-12-06 20:22:32 |
By :
...... |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถามต่ออีกนิด คือผมเอา code ไปแปลงเป็น VB ครับ
ผมไม่ค่อยรู้ C#
Code (VB.NET)
conn.Open()
cmd = New SqlCommand("select imgfile from myimages where imgname=@param", conn)
cmd.Parameters.Add("@param", SqlDbType.NVarChar, 30)
'myparam.Value = txtimgname.Text
Dim img As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
Dim str As New MemoryStream()
str.Write(img, 0, img.Length)
Dim bit As New Bitmap(str)
Response.ContentType = "image/jpeg"
bit.Save(Response.OutputStream, ImageFormat.Jpeg)
conn.Close()
ติดที่ response ครับ มันหมายความว่าไรอะครับ
|
 |
 |
 |
 |
Date :
2010-12-11 14:02:10 |
By :
stricken |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะบันทึกเป็น nvarchar นะ
|
 |
 |
 |
 |
Date :
2010-12-11 22:28:13 |
By :
kijjarcs50 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ^0^" 55
เอา bit ไปโยนลง picture box เลย
|
 |
 |
 |
 |
Date :
2010-12-12 14:19:43 |
By :
stricken |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าต้องการ แปลง bmp เป็น byte อ่ะคะ จะต้องทำไงอ่าาาาา
รบกวนด้วยคะ
|
 |
 |
 |
 |
Date :
2010-12-19 19:36:31 |
By :
ochin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนอธิบายหน่อยได้มั๊ยค่ะ เอาไปใช้แล้วมันERROR ตรง
cmd = New SqlCommand("select imgfile from myimages where imgname=@param", conn)
cmd.Parameters.Add("@param", SqlDbType.NVarChar, 30)
กับอันนี้ค่ะ
Response.ContentType = "image/jpeg"
bit.Save(Response.OutputStream, ImageFormat.Jpeg)
|
 |
 |
 |
 |
Date :
2010-12-19 21:27:39 |
By :
kimsumsun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโค้ดหน่อยคับ
ผมติดปัยหานี้เหมือนกัน
|
 |
 |
 |
 |
Date :
2011-02-08 18:39:19 |
By :
แช |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
conn.Open()
cmd = New SqlCommand("select imgfile from myimages where imgname=@param", conn)
cmd.Parameters.Add("@param", SqlDbType.NVarChar, 30)
'myparam.Value = txtimgname.Text
Dim img As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
Dim str As New MemoryStream()
str.Write(img, 0, img.Length)
Dim bit As New Bitmap(str)
PictureBox1.Image = bit
conn.Close()
เอาลง pictureBox แบบนี้หรือป่าวครับ
|
 |
 |
 |
 |
Date :
2012-07-09 23:07:20 |
By :
mamooba |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Response.ContentType = "image/jpeg"
Response คืออะไรอะครับ มันเป็นตัวแปรอะไร
พอเอาไปใช้ใน vb (win app)มัน error ว่า Name 'Response' is not declared. คือเราต้องประกาศตัวแปรว่าอะไรอะครับ
|
 |
 |
 |
 |
Date :
2012-08-09 14:37:58 |
By :
kimjung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวนี้ใช้ได้นะ
Code (VB.NET)
Dim cmd = New SqlCommand("select photo from Pic where P_name=@P_name", con)
cmd.Parameters.Add("@P_name", SqlDbType.NVarChar, 30).Value = TextBox_P_name.Text
Dim img As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
Dim str As New MemoryStream()
str.Write(img, 0, img.Length)
Dim bit As New Bitmap(str)
PictureBox1.Image = bit
|
ประวัติการแก้ไข 2016-09-07 13:08:23
 |
 |
 |
 |
Date :
2016-09-07 13:07:40 |
By :
new_user |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|