473,480 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get image to bytearray

Can anyone tell me what is wrong with this code?

I want to get the ocntents of the JPEG image into a byte array. After
the theStream.read call, the theBytes array is still filled with all
nulls. and iCount is zero.

I used this article
(http://msdn.microsoft.com/library/de...classtopic.asp)
as a starting point.

Thanks for any help

RichardF

Imports System
Imports System.IO
Imports System.Text
Imports System.Drawing

Module Module1

Sub Main()

Dim theImage As Image
Dim theStream As New MemoryStream
Dim theBytes As Byte()
Dim iCount As Integer

Try
theImage = Image.FromFile("C:\Images\Test.jpg")
theImage.Save(theStream, Imaging.ImageFormat.Jpeg)
theBytes = New Byte(theStream.Length - 1) {}
iCount = theStream.Read(theBytes, 0, theStream.Length - 1)
Catch ex As Exception
End Try

End Sub

End Module
Nov 19 '05 #1
2 1583
The most likely cause of the problem is security. By default the ASPNET
user account does not have access to that directory. Either grant it access
or have ASP.NET run under a different user account by using impersonation.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyAppUser">
password="password"/>

Here's more info on impersonation:
http://msdn.microsoft.com/library/de...ersonation.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"RichardF" <no***@nowhere.com> wrote in message
news:he********************************@4ax.com...
Can anyone tell me what is wrong with this code?

I want to get the ocntents of the JPEG image into a byte array. After
the theStream.read call, the theBytes array is still filled with all
nulls. and iCount is zero.

I used this article
(http://msdn.microsoft.com/library/de...classtopic.asp)
as a starting point.

Thanks for any help

RichardF

Imports System
Imports System.IO
Imports System.Text
Imports System.Drawing

Module Module1

Sub Main()

Dim theImage As Image
Dim theStream As New MemoryStream
Dim theBytes As Byte()
Dim iCount As Integer

Try
theImage = Image.FromFile("C:\Images\Test.jpg")
theImage.Save(theStream, Imaging.ImageFormat.Jpeg)
theBytes = New Byte(theStream.Length - 1) {}
iCount = theStream.Read(theBytes, 0, theStream.Length - 1)
Catch ex As Exception
End Try

End Sub

End Module

Nov 19 '05 #2
Although this will eventually be in a web service (hence the ASP.NET
group), currently I am testing the code in a console application.
Therefore I don't have a web.config and it should be running under the
currently logged in operator, not ASP.NET.

Any other ideas?

Thanks.

RichardF

On Wed, 16 Feb 2005 14:32:32 -0800, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.net> wrote:
The most likely cause of the problem is security. By default the ASPNET
user account does not have access to that directory. Either grant it access
or have ASP.NET run under a different user account by using impersonation.

For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyAppUser">
password="password"/>

Here's more info on impersonation:
http://msdn.microsoft.com/library/de...ersonation.asp


Nov 19 '05 #3

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

Similar topics

13
3707
by: PS | last post by:
I want to display the image from database to picture box through ado.net and vb.net I have some images present in a sql server 2000 table stored under 'image' datatype. I want to extract and...
3
4633
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per...
6
16104
by: Dean Slindee | last post by:
Does anybody have an actual example of retrieving an Image data type column from a SQL Server table using a dataset (not a datareader)? I would like to see the statements that would move the...
7
2271
by: BluDog | last post by:
Hi I am trying to store an image in an xml file, i vcan store it fine but the retreval is a bit of a problem: To String: Dim ms As New IO.MemoryStream Dim arrImage() As Byte...
3
5348
by: anewbie | last post by:
hi. ive been searching for help with storing images in access. after much hunting i found this bit of code that Cor Ligthert put up on another forum. but when i try to update to the dataset, i...
10
47868
by: Arno | last post by:
Hi, I want to convert a byte to a Image. I read in a newsgroup that the best way is to use a MemoryStream. I tried it, but I get always a Exception while creating the Image(An unhandled...
23
5856
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
1
4752
by: Gert Conradie | last post by:
The following code can uplaod text files. When i upload a binary file it fail. I might be: 1) using the wrong Encoding 2) will have to System.Convert.ToBase64String the content of the binary...
3
2618
kaleeswaran
by: kaleeswaran | last post by:
ResultSet rs=st.executeQuery("select i_sign from t_customer_photo where n_customer_id=1"); while(rs.next()) { byte...
2
2740
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
0
7054
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,...
0
7097
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...
0
6993
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...
1
4794
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...
0
4493
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...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.