Hi
I am trying to store an image in an xml file, i vcan store it fine but
the retreval is a bit of a problem:
To String:
Dim ms As New IO.MemoryStream
Dim arrImage() As Byte
Me.Image.Save(m s, System.Drawing. Imaging.ImageFo rmat.Jpeg)
arrImage = ms.GetBuffer
Dim UTF8 As New System.Text.UTF 8Encoding
Dim imageString as string = UTF8.GetString( arrImage)
Getting it back:
Dim UTF8 As New System.Text.UTF 8Encoding
Dim arrImage() As Byte = UTF8.GetBytes(i mageString)
Dim ms As New IO.MemoryStream (arrImage)
Me.Image = System.Drawing. Image.FromStrea m(ms)
Getting it back throws an error on the final line, "Invaid Parameter
Used". If i complete the above without saving it as the InnerText on
an XmlNode in betwen it works fine.
Any ideas would be great.
Thanks
blu 7 2285
* BluDog <ne**@nospam.bl udog.net> scripsit: Dim ms As New IO.MemoryStream Dim arrImage() As Byte Me.Image.Save(m s, System.Drawing. Imaging.ImageFo rmat.Jpeg) arrImage = ms.GetBuffer Dim UTF8 As New System.Text.UTF 8Encoding Dim imageString as string = UTF8.GetString( arrImage)
It won't solve your problem, but I suggest to use
'System.Text.En coding.UTF8' instead instantiating the encoding.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
BluDog,
I have made a complete sample that special in your case fits probably
completly
I hope it helps?
Cor
\\\needs a new project with on the form a picturebox and 4 buttons
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
'Reading a picture and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(f o.FileName, _
IO.FileMode.Ope n)
Dim br As New IO.BinaryReader (fs)
abyt = br.ReadBytes(CI nt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream (abyt)
Me.PictureBox1. Image = Image.FromStrea m(ms)
End If
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal _
e As System.EventArg s) Handles Button2.Click
'writing a picture from a bytearray
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(s f.FileName, _
IO.FileMode.Cre ateNew)
Dim bw As New IO.BinaryWriter (fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(B yVal sender As System.Object, ByVal _
e As System.EventArg s) Handles Button3.Click
'writing a bytearray to a dataset
Dim ds As New DataSet
ds.Tables.Add(N ew DataTable("Phot o"))
ds.Tables(0).Co lumns.Add(New DataColumn("Sam ple"))
ds.Tables(0).Co lumns(0).DataTy pe =
System.Type.Get Type("System.By te[]")
ds.Tables(0).Ro ws.Add(ds.Table s(0).NewRow)
ds.Tables(0).Ro ws(0)(0) = abyt
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
ds.WriteXml(sf. FileName, XmlWriteMode.Wr iteSchema)
End If
End Sub
Private Sub Button4_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button4.Click
'reading a picture from a dataset
Dim ds As New DataSet
If fo.ShowDialog = DialogResult.OK Then
ds.ReadXml(fo.F ileName)
End If
abyt = CType(ds.Tables (0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream (abyt)
Me.PictureBox1. Image = Image.FromStrea m(ms)
End Sub
///
On 07 Sep 2004 13:02:48 +0200, hi************* **@gmx.at (Herfried K.
Wagner [MVP]) wrote: * BluDog <ne**@nospam.bl udog.net> scripsit: Dim ms As New IO.MemoryStream Dim arrImage() As Byte Me.Image.Save(m s, System.Drawing. Imaging.ImageFo rmat.Jpeg) arrImage = ms.GetBuffer Dim UTF8 As New System.Text.UTF 8Encoding Dim imageString as string = UTF8.GetString( arrImage)
It won't solve your problem, but I suggest to use 'System.Text.E ncoding.UTF8' instead instantiating the encoding.
Herfried... yep, that makes sense. Cheers.
Probably a byte is added while saving.
Try to convert the byte array ToBase64 before saving,
and back after retrieval
Cor
Thanks, i can see this working, however in my application i want to
store the image as an XmlNode, the complete xml file looks like the
following:
- <Tags>
- <Tag id="e2c0fde4-f540-43e9-b0ac-0d7c94f2196f">
<Checked>Unchec ked</Checked>
<Text>Test Tag</Text>
<Expanded>Tru e</Expanded>
<Image type="base64Bin ary">JFIF
HHC $.' ",#(7),01444 '9=82<.342C
2!!2222222222 222222222222222 222222222222222 2222222222
"
}
!1AQa"q 2#BR$3br
%&'()*4567 89:CDEFGHIJSTUV WXYZcdefghijstu vwxyz
w
!1AQaq"2 B #3Rbr
$4%&'()*56 789:CDEFGHIJSTU VWXYZcdefghijst uvwxyz
??_^Nn+FQ.r8 gSdG#N
Qc-tEAA_} +BI ?U</Image>
</Tag>
</Tags>
The example you have given illustratess how to store the image as a
file in it's own right and as in xml format through a dataset, my
problem is that i want it to be a tag within an existing xml document.
The problem is that somewhere and i am not sure where there is data
being lost i believe when turning the image into a string:
Dim ms As New IO.MemoryStream
Me.Image.Save(m s, System.Drawing. Imaging.ImageFo rmat.Jpeg)
Dim imageBytes() As Byte = ms.GetBuffer
Dim imageString As String =
System.Text.Enc oding.UTF8.GetS tring(imageByte s)
Dim imageNode As XmlElement = CreateAppendEle ment(tagNode,
"Image")
imageNode.SetAt tribute("type", "base64Bina ry")
imageNode.Inner Text = imageString
I cannot find any references that create an xml representation of an
image as a part of a larger xml file.
Thanks
Blu.
On 7 Sep 2004 07:32:04 -0700, je***********@h otmail.com (jela) wrote: Probably a byte is added while saving. Try to convert the byte array ToBase64 before saving, and back after retrieval
Fantastic... thanks, for anyone else looking the solution based on the
OP:
To String:
Dim ms As New IO.MemoryStream
Me.Image.Save(m s, System.Drawing. Imaging.ImageFo rmat.Jpeg)
Dim imageString As String =
System.Convert. ToBase64String( ms.GetBuffer)
Dim imageNode As XmlElement = CreateAppendEle ment(tagNode,
"Image")
imageNode.SetAt tribute("type", "base64Bina ry")
imageNode.Inner Text = imageString
Getting it back:
Dim imageString As String = xmlNode("Image" ).InnerText
Dim imageBytes() As Byte =
System.Convert. FromBase64Strin g(imageString)
Dim ms As New IO.MemoryStream (imageBytes)
Me.Image = Me.Image.FromSt ream(ms)
Cheers
Blu
BluDog,
I changed my sample a little bit for you, I thought that it now fits your
needs.
Test program is included
I hope this helps?
Cor
\\\to test it needs 1 picturebox and 1 button on a form.
Private Function SerializeByte(B yVal _
imagestring As Byte()) As String
Dim bf As New Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(me m, imagestring)
Return Convert.ToBase6 4String(mem.ToA rray())
End Function
Private Function DeserializeStri ng(ByVal _
imagestring As String) As Byte()
Dim bf As New Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim mem As New IO.MemoryStream (Convert.FromBa se64String(imag estring))
Return DirectCast(bf.D eserialize(mem) , Byte())
End Function
''''''''''''''' ''''''''''''''' ''''''''''''''' '''''
'Test program
Private fo As New OpenFileDialog
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(f o.FileName, _
IO.FileMode.Ope n)
Dim br As New IO.BinaryReader (fs)
Dim abyt As Byte() = br.ReadBytes(CI nt(fs.Length))
br.Close()
Dim myresultstring As String = SerializeByte(a byt)
Dim abyt2 As Byte() = DeserializeStri ng(myresultstri ng)
Dim ms As New IO.MemoryStream (abyt2)
Me.PictureBox1. Image = Image.FromStrea m(ms)
End If
End Sub
/// This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob |
last post by:
My understanding of the image string function is this, that it allows the
display of text in Graphics
As per the parameters it receives:
ImageString($image,6,$xpos,$ypos,$out,$col)
these params:
1. name of thew image to write on
2. size of the font
3. X co-ordinate of the first letter of the string
|
by: Eshrath |
last post by:
Hi,
What I am trying to do:
=======================
I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are writing one object in C# which will take the entire table tag
contents and renders. Ie., we need to pass "<table>…………
<thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
|
by: Donald Firesmith |
last post by:
I am having trouble having Google Adsense code stored in XSL converted
properly into HTML. The <> unfortunately become < and > and then
no longer work.
XSL code is:
<script type="text/javascript">
<!]>
</script>
<script type="text/javascript"
|
by: Csaba2000 |
last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE
5.5+). This should work regardless of whether IE has focus. Normally you would do myDomElement.click and the mouse
doesn't matter, but in the case of an input image element, what happens is the submitted url has something like
"?x=12&y=7" appended to it (the numbers vary per mouse position on the clicked element). If you hit...
|
by: Frank Wein |
last post by:
Hi,
today i found out some browsers (at least Mozilla and IE) support the
<image> tag, its usage seems to be the same as for the <img> tag
(IMDB.com uses it for example). I did not find anything in the web so
far where this tag comes from (ok it's also a bit difficult to search
for this, since search engines all seem to ignore < or >), someone knows
more about this tag? I found some old reference that this tag at least
already existed in...
| |
by: ajay2552 |
last post by:
Hi,
I have a query.
All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it?
One method is to use <, > ,<Company> to display '<', '>' and '<Company>' respectively.
But is there any freeware code available which could implement the above functionality without having to use >,< and such stuff???
|
by: jross |
last post by:
I've looked all over Google for a solution for the disappearing background image in IE. My problem code looks like this -
<td colspan="3" background="../images/dots.gif"></td>
It obviously displays fine in FF but is something I just have to wear? I've tried a solution in the style sheet but the problem is the image spans more than one TD.
Any input would be appreciated.
Jonathan Ross
|
by: -Karl |
last post by:
Couls someone please advise me on this error. What I am trying to do
is be able to convert an XML document into arrays. I read that the
subs & functions have to be in <scripttags.
Thanks!
Error:
BC30456: 'Read_DOM' is not a member of
|
by: dimitri pater |
last post by:
---------- Forwarded message ----------
From: dimitri pater <dimitri.pater@gmail.com>
Date: Sep 5, 2007 9:13 PM
Subject: Re: StringIO MySQL data blob Image problem
To: Tim Golden <mail@timgolden.me.uk>
Dear Tim,
you are right of course, I have been trying to put the StringIO in a temp file:
cfoto=StringIO
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |