473,748 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializing System.Array HELP!

Hi All -

I've got a 3rd party COM object that returns an array of bytes that are a
TIFF image. After adding the reference to the com object to my solution the
C# signature
for the method is something like this:

System.Array Item.GetContent ();

I need to save the bytes to a file that will be the tiff file...so when I
see System.Array I think "serialization" . I have code like:

System.Array theBytes = anItem.GetConte nt();
FileStream fs = new FileStream("ima ge.tif", FileMode.Create );
BinaryFormatter formatter = new BinaryFormatter ();
formatter.Seria lize(fs, theBytes);
fs.Close();

Problem is, the serialize function adds more stuff to the file than just the
raw data and its no longer a valid TIFF!

The only way I could get it to work was to loop through the array and write
1 byte
at a time but performance is terrible! (And performance *is* an issue!)

Is ther a way to write the contents of System.Array as binary data quickly?
Or optionally, how do I convert System.Array to a byte[] (without looping
through all the data)?

Please help! I'm really stuck!
Aug 31 '06 #1
3 5461
Try the following:

byte[] theBytes = anItem.GetConte nt();
using (FileStream fs = File.Create("im age.tif"))
{
fs.Write (theBytes, 0, theBytes.Length );
fs.Close();
}

The only potential issue is the first line, I'm not sure what the signature
for GetContent is but basically you want it as a byte array (i.e. the
contents of the file).

HTH

- Andy

"clawton" <cl*****@discus sions.microsoft .comwrote in message
news:A2******** *************** ***********@mic rosoft.com...
Hi All -

I've got a 3rd party COM object that returns an array of bytes that are a
TIFF image. After adding the reference to the com object to my solution
the
C# signature
for the method is something like this:

System.Array Item.GetContent ();

I need to save the bytes to a file that will be the tiff file...so when I
see System.Array I think "serialization" . I have code like:

System.Array theBytes = anItem.GetConte nt();
FileStream fs = new FileStream("ima ge.tif", FileMode.Create );
BinaryFormatter formatter = new BinaryFormatter ();
formatter.Seria lize(fs, theBytes);
fs.Close();

Problem is, the serialize function adds more stuff to the file than just
the
raw data and its no longer a valid TIFF!

The only way I could get it to work was to loop through the array and
write
1 byte
at a time but performance is terrible! (And performance *is* an issue!)

Is ther a way to write the contents of System.Array as binary data
quickly?
Or optionally, how do I convert System.Array to a byte[] (without looping
through all the data)?

Please help! I'm really stuck!

Sep 1 '06 #2
Thanks for the reply...
I did try what you suggested and it wont compile. Error compiling is:
Cannot implicitly convert type 'System.Array' to 'byte[]'

"Andy Bates" wrote:
Try the following:

byte[] theBytes = anItem.GetConte nt();
using (FileStream fs = File.Create("im age.tif"))
{
fs.Write (theBytes, 0, theBytes.Length );
fs.Close();
}

The only potential issue is the first line, I'm not sure what the signature
for GetContent is but basically you want it as a byte array (i.e. the
contents of the file).

HTH

- Andy

"clawton" <cl*****@discus sions.microsoft .comwrote in message
news:A2******** *************** ***********@mic rosoft.com...
Hi All -

I've got a 3rd party COM object that returns an array of bytes that are a
TIFF image. After adding the reference to the com object to my solution
the
C# signature
for the method is something like this:

System.Array Item.GetContent ();

I need to save the bytes to a file that will be the tiff file...so when I
see System.Array I think "serialization" . I have code like:

System.Array theBytes = anItem.GetConte nt();
FileStream fs = new FileStream("ima ge.tif", FileMode.Create );
BinaryFormatter formatter = new BinaryFormatter ();
formatter.Seria lize(fs, theBytes);
fs.Close();

Problem is, the serialize function adds more stuff to the file than just
the
raw data and its no longer a valid TIFF!

The only way I could get it to work was to loop through the array and
write
1 byte
at a time but performance is terrible! (And performance *is* an issue!)

Is ther a way to write the contents of System.Array as binary data
quickly?
Or optionally, how do I convert System.Array to a byte[] (without looping
through all the data)?

Please help! I'm really stuck!


Sep 1 '06 #3
Duh! I just got it!
Just cast the dumb thing! :)
Thanks again!

"clawton" wrote:
Thanks for the reply...
I did try what you suggested and it wont compile. Error compiling is:
Cannot implicitly convert type 'System.Array' to 'byte[]'

"Andy Bates" wrote:
Try the following:

byte[] theBytes = anItem.GetConte nt();
using (FileStream fs = File.Create("im age.tif"))
{
fs.Write (theBytes, 0, theBytes.Length );
fs.Close();
}

The only potential issue is the first line, I'm not sure what the signature
for GetContent is but basically you want it as a byte array (i.e. the
contents of the file).

HTH

- Andy

"clawton" <cl*****@discus sions.microsoft .comwrote in message
news:A2******** *************** ***********@mic rosoft.com...
Hi All -
>
I've got a 3rd party COM object that returns an array of bytes that are a
TIFF image. After adding the reference to the com object to my solution
the
C# signature
for the method is something like this:
>
System.Array Item.GetContent ();
>
I need to save the bytes to a file that will be the tiff file...so when I
see System.Array I think "serialization" . I have code like:
>
System.Array theBytes = anItem.GetConte nt();
FileStream fs = new FileStream("ima ge.tif", FileMode.Create );
BinaryFormatter formatter = new BinaryFormatter ();
formatter.Seria lize(fs, theBytes);
fs.Close();
>
Problem is, the serialize function adds more stuff to the file than just
the
raw data and its no longer a valid TIFF!
>
The only way I could get it to work was to loop through the array and
write
1 byte
at a time but performance is terrible! (And performance *is* an issue!)
>
Is ther a way to write the contents of System.Array as binary data
quickly?
Or optionally, how do I convert System.Array to a byte[] (without looping
through all the data)?
>
Please help! I'm really stuck!
Sep 1 '06 #4

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

Similar topics

1
3276
by: Ryan Hubbard | last post by:
I've have been trying to serialize an array of objects. I can serialize and set a session variable and retrieve it successfully for a serialize string of any length within the contents of a single script. $_SESSION = serialize($b); // strlen($a) = 120,011 print unserialize($_SESSION) But if I set a session variable and then try to access it on another
4
7830
by: Christopher Pragash | last post by:
Hello all, Following is the code that I'm using to serialize an arraylist. This code returns an "Unknown" Errror. Any ideas would be of great help. <System.Xml.Serialization.XmlArray(), _ System.Xml.Serialization.XmlArrayItem("User", GetType(User))> Public arrUserList As New ArrayList Private Function InitializeList() As ArrayList
0
2825
by: Tom Kent | last post by:
I have an array list of objects that I want to serialize into an XML file. I have tried this using the following code, but it gives me an error message An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dl Additional information: There was an error generating the XML document I'm not sure if this is the way that I should go about serializing an array of objects like this, but I would like to get them...
4
2732
by: Wayne Wengert | last post by:
I am still stuck trying to create a Class to use for exporting and importing array data to/from XML. The format of the XML that I want to import/export is shown below as is the Class and the code I am using to create a sample XML file. I am trying to dimension the ArrayOfJudgeEntity to have two sets of the JudgeTableEntity values. When I run the code I get an error that the XML is not correct. I jsut can't get my head around the array...
3
3169
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on the server (W2K3) it throws an exception. It only seems to happen when serializing/deserializing _arrays_ of a type. If I just serialize/deserialize one instance, it works fine. The exception I get is: (sorry for the word wrapping.)...
1
5403
by: Chris | last post by:
I'm having trouble Serializing a System.Data.DataColumn object. When I try to serialize it, I get the following: System.NotSupportedException: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface. I tried a number of workarounds without sucess:
2
1354
by: Rick Francis | last post by:
I need help serializing an array without including the array "name". I am writing in C# and using the XmlSerializer to serial classes. I am trying to serialize a class with an array in it like the one below. public class myclass { public imagecontext; public myimage images; }
2
1484
by: Rick Francis | last post by:
I need help serializing an array without including the array "name". I am writing in C# and using the XmlSerializer to serial classes. I am trying to serialize a class with an array in it like the one below. public class myclass { public imagecontext; public myimage images; }
6
3182
by: Kyle Teague | last post by:
What would give better performance, serializing a multidimensional array and storing it in a single entry in a table or storing each element of the array in a separate table and associating the entries with the entry in the other table? Having a separate table would result in two queries instead of one, but you wouldn't have to deal with the overhead of serializing and unserializing data. -- Kyle
0
8832
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,...
0
9558
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9378
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9253
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 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...
0
8250
agi2029
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...
1
6798
isladogs
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...
0
6077
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();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.