473,395 Members | 1,474 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,395 software developers and data experts.

How to convert an Image into a Byte array?

Don
Is there any way to convert an Image into a Byte array that does not require
saving the image to disk?

- Don
Nov 21 '05 #1
2 5119
"Don" <un*****@oblivion.com> schrieb:
Is there any way to convert an Image into a Byte array that does not
require
saving the image to disk?


Save the image to a 'MemoryStream' object. 'MemoryStream' has a 'ToArray'
method which will return the bytes stored in the stream.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Don,

I was sure I had a sample for this, I was wrong, so I made a new one.
(Your problem is in the button event part)

\\\The sample needs two pictureboxes and a button on a form
Private Sub Form1_Load(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fo As New OpenFileDialog
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
Dim abyt As Byte()
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim abyt As Byte()
Dim ms As New IO.MemoryStream
PictureBox1.Image.Save(ms, Imaging.ImageFormat.Bmp)
abyt = ms.GetBuffer
Dim ms2 As New IO.MemoryStream(abyt)
Me.PictureBox2.Image = Image.FromStream(ms2)
Me.PictureBox1.Image = Nothing
End Sub
////
I hope this helps a little bit?

Cor
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: PHS | last post by:
I have a c# client application that connects to a network socket. When connected, the listener sends a network stream containing bitmap, jpeg, data from a file nominated by the client. The client...
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
2
by: Clas Hortien | last post by:
Hi, i have a array of uint and want to display this array as a System.Web.UI.WebControls.Image. //========================================= uint ar = new uint; string fName;
7
by: Rob T | last post by:
Hi, I'm trying to convert his line from C# to VB: System.Drawing.Image _img= System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte)SqlReader); I have this so far: dim Img as...
3
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As...
5
by: Trammel | last post by:
Hi, I have a vb.net program made to grab screenshots and then store them in image objects. The image is displayed in a pictureBox atm but I want to store the data in a String only. (Without...
8
by: piggy | last post by:
I am trying to convert an image to an byte array (tobytes() method) and from byte array back to an image (frombytes() method). The problem i have here is say the image size is 285 bytes but the...
2
by: minouparhizkar | last post by:
hi could anyone helping me to finish this i have no idea how to implement the program in java im trying to grabbing the pixel from image and then convert it to the txt file .i did that but it didnt...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.