473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 11618
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: PHS | last post by:
I have a c# client application that connects to a network socket. When connected, the listener sends a network stream containing bitmap, jpeg, data from a file nominated by the client. The client...
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
2
by: Clas Hortien | last post by:
Hi, i have a array of uint and want to display this array as a System.Web.UI.WebControls.Image. //========================================= uint ar = new uint; string fName;
7
by: Rob T | last post by:
Hi, I'm trying to convert his line from C# to VB: System.Drawing.Image _img= System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte)SqlReader); I have this so far: dim Img as...
3
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As...
5
by: Trammel | last post by:
Hi, I have a vb.net program made to grab screenshots and then store them in image objects. The image is displayed in a pictureBox atm but I want to store the data in a String only. (Without...
2
by: minouparhizkar | last post by:
hi could anyone helping me to finish this i have no idea how to implement the program in java im trying to grabbing the pixel from image and then convert it to the txt file .i did that but it didnt...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...
0
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...
0
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,...

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.