472,096 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 software developers and data experts.

convert image to byte array and the other way?

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.
Jul 17 '06 #1
8 11423
What is the image size and total size? How do you calculate the image size?
--
Stoitcho Goutsev (100)

"piggy" <pi***@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
>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.

Jul 17 '06 #2
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" <pi***@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
>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.

Jul 17 '06 #3
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" <pi***@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
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.
Jul 17 '06 #4
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.
Jul 17 '06 #5
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.
Jul 17 '06 #6
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.
Jul 18 '06 #7
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" <pi***@discussions.microsoft.comwrote in message
news:6F**********************************@microsof t.com...
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.


Jul 18 '06 #8
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.
Jul 18 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Swarup | last post: by
1 post views Thread by Fritz Switzer | last post: by
2 posts views Thread by Clas Hortien | last post: by
7 posts views Thread by Rob T | last post: by
reply views Thread by leo001 | last post: by

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.