473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to convert byte array into image itself and show it in PictureBox1?

1
Hello Everyone, I have a Problems Regarding with the

IMAGE
I create a Program That save Information of END USERS including Image... but the Image will save into Bytes.....and I have no Problem in that as you seen below.....

Expand|Select|Wrap|Line Numbers
  1. Dim xx As String = "insert into tbl_BorrowersInfo (accountno, sname, fname, mname, photo) values ('" & txt_AccountNo.Text & "','" & txt_SNme.Text & "','" & txt_FName.Text & "','" & txt_MI.Text & "', @photo)"
  2.                     Dim cmd As New SqlCommand(xx, con)
  3.                     Dim ms As New MemoryStream()
  4.  
  5.                     PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
  6.                     Dim data As Byte() = ms.GetBuffer()
  7.                     Dim p As New SqlParameter("@photo", SqlDbType.Image)
  8.                     p.Value = data
  9.                     cmd.Parameters.Add(p)
  10.                     cmd.ExecuteNonQuery()
  11.  
This is My Problem i have this Search Engine that can Search information that can show the information needed from the database....... it works Nicely but I don't know how to show/Retrieve the Image from Bytes to Image itself and show it into the PictureBox1.. the code shown Below.. Please Help me.. thanks..


Expand|Select|Wrap|Line Numbers
  1. con.Open()
  2.         Dim ab As New SqlCommand("select accountno,sname, fname, mname,photo from tbl_BorrowersInfo where accountno like '%" & searchstring & "%' or sname like '%" & searchstring & "%' or fname like '%" & searchstring & "%' or mname like '%" & searchstring & "%'", con)
  3.         Dim bc As SqlDataReader = ab.ExecuteReader()
  4.         bc.Read()
  5.         If bc.HasRows Then
  6.  
  7.             If bc.HasRows Then
  8.                 txt_No.Text = bc("no")
  9.                 txt_AccountNo.Text = bc("accountno")
  10.                 cmb_ReaderType.Text = bc("usertype")
  11.                 txt_SNme.Text = bc("sname")
  12.                 txt_FName.Text = bc("fname")
  13.                 txt_MI.Text = bc("mname")
  14.                 PictureBox1.Image = bc("photo")
  15. End If()
  16. con.Close()
Feb 28 '12 #1
2 5328
Gopi
5
Hi Friend, It is simple i give sample code below i just use this next button click event to retrieve images from database you just edit as ur need,
Expand|Select|Wrap|Line Numbers
  1.  
  2.   Dim da As SqlDataAdapter
  3.             Dim ds As New DataSet
  4.             dbconnection()
  5.  
  6.             con.Open()
  7.  
  8.             da = New SqlDataAdapter("SELECT Picture FROM imagestore", con)
  9.  
  10.             da.Fill(ds)
  11.  
  12.             con.Close()
  13.  
  14.             Dim k As Integer = ds.Tables(0).Rows.Count
  15.  
  16.             i = i + 1
  17.  
  18.             If i < k Then
  19.                 PictureBox1.Image = Image.FromStream(New MemoryStream(DirectCast(ds.Tables(0).Rows(i).ItemArray(0), Byte())))
  20.             Else
  21.                 i = 0
  22.                 PictureBox1.Image = Image.FromStream(New MemoryStream(DirectCast(ds.Tables(0).Rows(i).ItemArray(0), Byte())))
  23.             End If 
Mar 27 '12 #2
!NoItAll
297 100+
Expand|Select|Wrap|Line Numbers
  1.     Public Function Byte2Image(ByVal ByteArr() As Byte) As Image
  2.         'will turn a byte array to an image
  3.         Dim ImageStream As MemoryStream
  4.  
  5.         Try
  6.             If ByteArr.GetUpperBound(0) > 0 Then
  7.                 ImageStream = New MemoryStream(ByteArr)
  8.                 Return Image.FromStream(ImageStream)
  9.             Else
  10.                 Return Nothing
  11.             End If
  12.         Catch ex As Exception
  13.             Return Nothing
  14.         End Try
  15.  
  16.     End Function
Mar 29 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Gator | last post by:
Hi All, Basically my situation is this, I have a server implemented in C++, unmanaged code, using proprietery protocol over TCP/IP to communicate with the cilent(c++ also). Now, I am implementing...
5
by: Andrew Inwards | last post by:
Can anyone tell me how to convert a byte array to a stream.? Thanks Andrew
4
by: Dan | last post by:
I need to convert a byte array to a string in order to upload a binary file with an httpWebRequest. What's the most efficient way to do such a conversion?
2
by: Dave | last post by:
Hi, I'm trying to convert a byte array to string --This works... System.BitConverter.ToString(bytes) "EB-55-79-20-18-B2-76-4D-85-0A-93-6B-97-33-31-B8" --This doesn't, but returns...
5
by: Terry Olsen | last post by:
Looking for info on how to convert a byte array to a string, and string to byte array. Thanks.
14
by: Charles Law | last post by:
I thought this had come up before, but I now cannot find it. I have a byte array, such as Dim a() As Byte = {1, 2, 3, 4} I want to convert this to an Int32 = 01020304 (hex). If I use...
2
by: shiplu | last post by:
I have an image which I make a byte array. Now I want to store the byte array to the database server through jsp. I have created table & query string. I am facing problem to send request to the jsp
0
by: Sergei Shelukhin | last post by:
Hi. I receive a byte array that contains utf-16 string (with a lot of \0 characters :)) from a legacy system that holds some data that is changed elsewhere. How do I convert it to an actual utf-16...
18
by: MrVS | last post by:
Hi, I have a C++ CLR class method that takes System::Byte *b as parameter argument. I want the CSharp caller pass a byte * to this function. But in the CSharp prorgram, I only managed to create a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.