PC Review


Reply
Thread Tools Rate Thread

convert image to byte array and the other way?

 
 
=?Utf-8?B?cGlnZ3k=?=
Guest
Posts: n/a
 
      17th Jul 2006
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 total bytes is 635. I know it would
include the header but the header should be the same size regardless of the
image size. I tested the other image size of 407 bytes and the total bytes
array is 727. I am not sure what is wrong? your help would be appreciate
it.
 
Reply With Quote
 
 
 
 
Stoitcho Goutsev \(100\)
Guest
Posts: n/a
 
      17th Jul 2006
What is the image size and total size? How do you calculate the image size?


--
Stoitcho Goutsev (100)

"piggy" <(E-Mail Removed)> wrote in message
news:6FED606A-BD1F-4F8C-B6F2-(E-Mail Removed)...
>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 total bytes is 635. I know it
> would
> include the header but the header should be the same size regardless of
> the
> image size. I tested the other image size of 407 bytes and the total
> bytes
> array is 727. I am not sure what is wrong? your help would be appreciate
> it.



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      17th Jul 2006
Hi,

What is the problem with a variable size?

Just handle the entire array as one entity.

You can you use a MemoryStream to convert to/from byte


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"piggy" <(E-Mail Removed)> wrote in message
news:6FED606A-BD1F-4F8C-B6F2-(E-Mail Removed)...
>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 total bytes is 635. I know it
> would
> include the header but the header should be the same size regardless of
> the
> image size. I tested the other image size of 407 bytes and the total
> bytes
> array is 727. I am not sure what is wrong? your help would be appreciate
> it.



 
Reply With Quote
 
JustinC
Guest
Posts: n/a
 
      17th Jul 2006
If you have an image, you can have a file. If you have a file you have
a filestream. If you have a filestream you can get an array of bytes.
You might have to mess around with what streams you need, probably a
mix of FileStream and MemoryStream.

Ignacio Machin ( .NET/ C# MVP ) wrote:
> Hi,
>
> What is the problem with a variable size?
>
> Just handle the entire array as one entity.
>
> You can you use a MemoryStream to convert to/from byte
>
>
> --
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>
> "piggy" <(E-Mail Removed)> wrote in message
> news:6FED606A-BD1F-4F8C-B6F2-(E-Mail Removed)...
> >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 total bytes is 635. I know it
> > would
> > include the header but the header should be the same size regardless of
> > the
> > image size. I tested the other image size of 407 bytes and the total
> > bytes
> > array is 727. I am not sure what is wrong? your help would be appreciate
> > it.


 
Reply With Quote
 
Tom Spink
Guest
Posts: n/a
 
      17th Jul 2006
piggy wrote:

> 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 total bytes is 635. I know it
> would include the header but the header should be the same size regardless
> of the
> image size. I tested the other image size of 407 bytes and the total
> bytes
> array is 727. I am not sure what is wrong? your help would be appreciate
> it.


Hi Piggy,

Can you post some code, demonstrating what you are doing, and how you are
obtaining 'image size' and 'total bytes'?

--
Hope this helps,
Tom Spink

Google first, ask later.
 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      17th Jul 2006
Your Image Class sports a Save and a FromStream method, both of which can
work with a stream such as a MemoryStream. MemoryStream class has a
contructor overload that accepts a byte array, and it has a ToArray method
that gives you back a byte array. The header (Jpeg, gif, etc is simply part
of this array and you should not need to worry about it at all.
Hope that helps,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"piggy" wrote:

> 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 total bytes is 635. I know it would
> include the header but the header should be the same size regardless of the
> image size. I tested the other image size of 407 bytes and the total bytes
> array is 727. I am not sure what is wrong? your help would be appreciate
> it.

 
Reply With Quote
 
=?Utf-8?B?cGlnZ3k=?=
Guest
Posts: n/a
 
      18th Jul 2006
The problem is that we try to send as small as package size over the network
as possible. I am just curious. If that is how it works and there are no
ways to fix it then have to accept it. Thanks for your comments.

"Peter Bromberg [C# MVP]" wrote:

> Your Image Class sports a Save and a FromStream method, both of which can
> work with a stream such as a MemoryStream. MemoryStream class has a
> contructor overload that accepts a byte array, and it has a ToArray method
> that gives you back a byte array. The header (Jpeg, gif, etc is simply part
> of this array and you should not need to worry about it at all.
> Hope that helps,
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "piggy" wrote:
>
> > 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 total bytes is 635. I know it would
> > include the header but the header should be the same size regardless of the
> > image size. I tested the other image size of 407 bytes and the total bytes
> > array is 727. I am not sure what is wrong? your help would be appreciate
> > it.

 
Reply With Quote
 
=?Utf-8?B?cGlnZ3k=?=
Guest
Posts: n/a
 
      18th Jul 2006
i don't calculate the image size. I just check the image size from window
explorer. Is there a way to do it?

"Stoitcho Goutsev (100)" wrote:

> What is the image size and total size? How do you calculate the image size?
>
>
> --
> Stoitcho Goutsev (100)
>
> "piggy" <(E-Mail Removed)> wrote in message
> news:6FED606A-BD1F-4F8C-B6F2-(E-Mail Removed)...
> >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 total bytes is 635. I know it
> > would
> > include the header but the header should be the same size regardless of
> > the
> > image size. I tested the other image size of 407 bytes and the total
> > bytes
> > array is 727. I am not sure what is wrong? your help would be appreciate
> > it.

>
>
>

 
Reply With Quote
 
=?Utf-8?B?cGlnZ3k=?=
Guest
Posts: n/a
 
      18th Jul 2006
I agree that header is a part of the array but shoudn't it be the same size
regarless of the image size? It will be different depending on the image
type as well.

"piggy" wrote:

> The problem is that we try to send as small as package size over the network
> as possible. I am just curious. If that is how it works and there are no
> ways to fix it then have to accept it. Thanks for your comments.
>
> "Peter Bromberg [C# MVP]" wrote:
>
> > Your Image Class sports a Save and a FromStream method, both of which can
> > work with a stream such as a MemoryStream. MemoryStream class has a
> > contructor overload that accepts a byte array, and it has a ToArray method
> > that gives you back a byte array. The header (Jpeg, gif, etc is simply part
> > of this array and you should not need to worry about it at all.
> > Hope that helps,
> > Peter
> >
> > --
> > Co-founder, Eggheadcafe.com developer portal:
> > http://www.eggheadcafe.com
> > UnBlog:
> > http://petesbloggerama.blogspot.com
> >
> >
> >
> >
> > "piggy" wrote:
> >
> > > 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 total bytes is 635. I know it would
> > > include the header but the header should be the same size regardless of the
> > > image size. I tested the other image size of 407 bytes and the total bytes
> > > array is 727. I am not sure what is wrong? your help would be appreciate
> > > it.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert an Image into a Byte array? Don Microsoft VB .NET 2 5th Jul 2005 05:03 PM
How do I convert a ASCII Byte Array, to another Byte Array Russell Mangel Microsoft Dot NET Framework 2 2nd Feb 2005 06:01 PM
Re: Convert byte array to an Image Ken Cox [Microsoft MVP] Microsoft ASP .NET 0 3rd Jun 2004 02:09 PM
How to Convert Binary Coded Hex Byte Array to Byte Charles Law Microsoft VB .NET 25 2nd Jun 2004 02:21 PM
Convert native byte array (pointer) to managed byte[] Dave Microsoft Dot NET 1 13th Aug 2003 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:43 PM.