Hi,
In my application I receive a Byte Stream (Dim bytFile() As Byte) which
contains a jpeg-picture, which I want to display in a picturebox.
I want to display it directly from the bytfile() without first writing it to
a file and than reading it. Does anybody knows how to do this?
I hae alreaddy a solution with writing it to a file, but the next time i
want to do it I get an exception that the file is still in sue when I want
to write to it. So to get aroudn this kind of problems I want something
without file...
My code with the file:
Dim strPicLoc As String
strPicLoc = "C:\test.jpeg"
'picture
RetStatus = EIDlib1.GetPicture(MapColPicture, CertifCheck)
Dim br As New BinaryWriter(File.OpenWrite(strPicLoc))
Dim bytFile() As Byte
bytFile = MapColPicture.GetValue("Picture")
br.Write(bytFile)
br.Flush()
br.Close()
br = Nothing
'show the picture in the picturebox!
picPicture.Image = Image.FromFile(strPicLoc)
Thanks a lot in advance,
Pieter 4 2125
Ok I found it alreaddy myself!
Thanks anyways!
Dim bytFile() As Byte
bytFile = MapColPicture.GetValue("Picture")
'show the picture in the picturebox!
Dim mstr As New MemoryStream(bytFile)
picPicture.Image = Image.FromStream(mstr)
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:OC**************@TK2MSFTNGP15.phx.gbl... Hi,
In my application I receive a Byte Stream (Dim bytFile() As Byte) which contains a jpeg-picture, which I want to display in a picturebox.
I want to display it directly from the bytfile() without first writing it
to a file and than reading it. Does anybody knows how to do this? I hae alreaddy a solution with writing it to a file, but the next time i want to do it I get an exception that the file is still in sue when I want to write to it. So to get aroudn this kind of problems I want something without file...
My code with the file: Dim strPicLoc As String strPicLoc = "C:\test.jpeg" 'picture RetStatus = EIDlib1.GetPicture(MapColPicture, CertifCheck) Dim br As New BinaryWriter(File.OpenWrite(strPicLoc)) Dim bytFile() As Byte bytFile = MapColPicture.GetValue("Picture") br.Write(bytFile) br.Flush() br.Close() br = Nothing
'show the picture in the picturebox! picPicture.Image = Image.FromFile(strPicLoc)
Thanks a lot in advance,
Pieter
DraguVaso <pi**********@hotmail.com> wrote: In my application I receive a Byte Stream (Dim bytFile() As Byte) which contains a jpeg-picture, which I want to display in a picturebox.
That's not a byte stream - that's a byte array.
I want to display it directly from the bytfile() without first writing it to a file and than reading it. Does anybody knows how to do this?
Sure - construct a MemoryStream with the byte array, and then use
Image.FromStream.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Pieter,
You have your answer, however here it is more complete so that you can do
all actions with it when it is your next question about a database. I have
eliminiated the to much writing using a memorystream what is mostly showed
in samples, although in your question that is needed and used as last part
in the sample.
Maybe you can use it.
Cor
\\\it needs a picturebox and four buttons on a page.
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType =
System.Type.GetType("System.Byte[]")
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.FileName)
End If
abyt = CType(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
///
Cor
Thanks Cor!
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl... Pieter,
You have your answer, however here it is more complete so that you can do all actions with it when it is your next question about a database. I have eliminiated the to much writing using a memorystream what is mostly showed in samples, although in your question that is needed and used as last part in the sample.
Maybe you can use it.
Cor
\\\it needs a picturebox and four buttons on a page. Private abyt() As Byte Private fo As New OpenFileDialog Private sf As New SaveFileDialog Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Reading a picture and put it in a bytearray If fo.ShowDialog = DialogResult.OK Then Dim fs As New IO.FileStream(fo.FileName, _ IO.FileMode.Open) Dim br As New IO.BinaryReader(fs) abyt = br.ReadBytes(CInt(fs.Length)) br.Close() 'just to show the sample without a fileread error Dim ms As New IO.MemoryStream(abyt) Me.PictureBox1.Image = Image.FromStream(ms) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles Button2.Click 'writing a picture from a bytearray If sf.ShowDialog = DialogResult.OK Then Dim fs As New IO.FileStream(sf.FileName, _ IO.FileMode.CreateNew) Dim bw As New IO.BinaryWriter(fs) bw.Write(abyt) bw.Close() End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles Button3.Click 'writing a bytearray to a dataset Dim ds As New DataSet ds.Tables.Add(New DataTable("Photo")) ds.Tables(0).Columns.Add(New DataColumn("Sample")) ds.Tables(0).Columns(0).DataType = System.Type.GetType("System.Byte[]") ds.Tables(0).Rows.Add(ds.Tables(0).NewRow) ds.Tables(0).Rows(0)(0) = abyt Dim sf As New SaveFileDialog If sf.ShowDialog = DialogResult.OK Then ds.WriteXml(sf.FileName, XmlWriteMode.WriteSchema) End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button4.Click 'reading a picture from a dataset Dim ds As New DataSet If fo.ShowDialog = DialogResult.OK Then ds.ReadXml(fo.FileName) End If abyt = CType(ds.Tables(0).Rows(0)(0), Byte()) Dim ms As New IO.MemoryStream(abyt) Me.PictureBox1.Image = Image.FromStream(ms) End Sub ///
Cor
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim Streater |
last post by:
I want to generate a web page using PHP, and in the middle generate a
graphic I read from another server. So the graphic is in $picture. So I
can either write $picture to a temp file and then use...
|
by: Peter |
last post by:
Hi
how can I compare two byte arrays in VB.NET
Thank
Peter
|
by: CSN |
last post by:
Is it possible to iterate over an array in plpgsql?
Something like:
function insert_stuff (rel_ids int)
....
foreach rel_ids as id
insert into table (rel_id, val)
values (id, 5);
|
by: Dennis Myrén |
last post by:
Hi.
Is there a way to utilize the great primitive data type
formatting routines available in .NET without working with
strings?
I want a byte directly rather than a string.
I think it is...
|
by: ATS |
last post by:
HOWTO Make a UserControl deploy an embedded resource.
Please help,
I need to embed an EXE into a C# UserControl that is run from script in an
HTML web page as such:
<html>
<object...
|
by: ATS |
last post by:
HOWTO Make a C# UserContol Memory Map to a C++/MFC/EXE
Please help,
I have a UserControl that I want to have "talk" to a C++/MFC/EXE program
that is already running via a memory map.
The...
|
by: ATS |
last post by:
HOWTO Read from stdout without blocking.
Please help,
I have an app that is launching another process, where it is letting the new
process inherit the STD-IN/OUT hanldes. The goal is to let...
|
by: Roy |
last post by:
Hi,
I have a problem that I have been working with for a while.
I need to be able from server side (asp.net) to detect that the file i'm
streaming down to the client is saved...
|
by: Lee Gillie |
last post by:
I am using Cryptography. You can encrypt or decrypt by providing an
output stream as a parameter to the CryptoStream constructor. But I
need byte arrays, as I am encrypting on the fly to a socket,...
|
by: fnoppie |
last post by:
Hi,
I am near to desperation as I have a million things to get a solution
for my problem. I have to post a multipart message to a url that
consists of a xml file and an binary file (pdf)....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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: 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...
|
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...
| |