473,378 Members | 1,355 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,378 software developers and data experts.

image to byte array problems...

I'm trying to convert an image to a byte array. However, when i do this
something is getting changed in the bytes (contents, length, etc). I
know because I'm also looking at the image bytes in a hex editor. I
want the image bytes in the program to match those that i'm looking at
in the hex editor. I'm not sure if it's an encoding thing or something
else.Here's the code I'm using:

Public Function ToArray(System.Drawing.Image img)

Dim ms As MemoryStream = New MemoryStream()
img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
Return ms.ToArray()

End Function

Also, I'd like to not have to specify the ImageFormat type.

Thanks,
todd

Nov 21 '05 #1
5 1724
Is there a reason your using the memory stream? Are you reading this image
out of sql?

take a look at this link
It will tell you how to read and write an image to blob data. In which your
turing your insert statement in to a bite array

http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp
<to********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to convert an image to a byte array. However, when i do this
something is getting changed in the bytes (contents, length, etc). I
know because I'm also looking at the image bytes in a hex editor. I
want the image bytes in the program to match those that i'm looking at
in the hex editor. I'm not sure if it's an encoding thing or something
else.Here's the code I'm using:

Public Function ToArray(System.Drawing.Image img)

Dim ms As MemoryStream = New MemoryStream()
img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
Return ms.ToArray()

End Function

Also, I'd like to not have to specify the ImageFormat type.

Thanks,
todd

Nov 21 '05 #2
It has nothing to do with Sql specifically. For various job related
stuff, I need to inspect the actual bytes of the image. The image might
be coming from Sql, or a file, or a memory stream.

todd

Nov 21 '05 #3
yes if you look at that link i sent you it reads bytes out of sql. You can
do the same thing from a file or from memory stream does not matter

<to********@hotmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
It has nothing to do with Sql specifically. For various job related
stuff, I need to inspect the actual bytes of the image. The image might
be coming from Sql, or a file, or a memory stream.

todd

Nov 21 '05 #4
Yes, I know how to do that already. (See my first post...)

The problem is this: something is changing the bytes during the
conversion to the byte array. I want the byte array to match what i see
when opening the image in a hex editor.

t

Nov 21 '05 #5
Sorry about that... Ok so your trying to compare bytes of an image.
they should not be getting screwed up.. I guess i would be in same spot as
you..
Idea for you to try

Try making 2 picture boxs ... visibile hidden.
create the images in the picture boxes
then compare bit to bit.

I am sorry I can not answer if the bytes are being encoded. But they should
not be from what i understand about the stream process.

question:
If you display the image does it come out right?

<to********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I'm trying to convert an image to a byte array. However, when i do this
something is getting changed in the bytes (contents, length, etc). I
know because I'm also looking at the image bytes in a hex editor. I
want the image bytes in the program to match those that i'm looking at
in the hex editor. I'm not sure if it's an encoding thing or something
else.Here's the code I'm using:

Public Function ToArray(System.Drawing.Image img)

Dim ms As MemoryStream = New MemoryStream()
img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
Return ms.ToArray()

End Function

Also, I'd like to not have to specify the ImageFormat type.

Thanks,
todd

Nov 21 '05 #6

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

Similar topics

8
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
5
by: Neo Geshel | last post by:
I still have a problem displaying images from an access DB using asp.net. This showimage.aspx is for an admin site. I need to pull the correct image from the correct table, hence the two GET...
1
by: Mchuck | last post by:
I've seen several newsgroup topics everywhere concerning this, as well as a couple of articles from the MSDN website, but this error still baffles me. It has to do with using the...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
9
by: Tom John | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
0
by: sebascomeau | last post by:
Hi everyone, Hello my name is Sebastien and I need some help. He have one week past and I search to do one thing but I can't. If someone help me, I'll be so happy :). My problem is I want to...
10
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should...
9
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.