Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert an image ino an image object from a filestream?

Status
Not open for further replies.

Sanjeet1

Programmer
Sep 4, 2003
26
US
When I call this web service I receive a byte array that contains an image.

The web page that calls the web service contains an Image object.

I need to display the mage. Here is my code. How do I retreive the image from the byte array and insert it into the Image object?

'Call Webservice to pass 3 parameters
Dim WS As New ImageRetreival.WS1.GetImage
Dim ImageDB As Byte()
ImageDB(0) = WS.RetreiveImageDB(userid, patientid, recordid)
Dim strfn As String = Convert.ToString(DateTime.Now.ToFileTime)
Dim fs As New FileStream(strfn, FileMode.CreateNew, FileAccess.Write)
fs.Write(ImageDB, 0, ImageDB.Length)
fs.Flush()
fs.Close()




Image1 = ????? / This is where I need help
 
'Call Webservice to pass 3 parameters

Dim WS As New ImageRetreival.WS1.GetImage

Dim ImageDB As Byte()

'Dim d As System.Text.Encoding

' ImageDB(0) = WS.RetreiveImageDB(userid, patientid, recordid)

Dim ImgDbstr As String = WS.RetreiveImageDB(userid, patientid, recordid)

'btyes = Convert.FromBase64String(string)

ImageDB = Convert.FromBase64String(ImgDbstr)

Dim ms As New System.IO.MemoryStream(ImageDB)

Dim img As System.Drawing.Image

img.FromStream(ms)

img.Save(Server.MapPath("filename"))

img.Dispose()

ms.Close()

ms.Flush()


This is my error messsage:



Server Error in '/ImageRetreival' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 77: Dim img As System.Drawing.Image
Line 78: img.FromStream(ms)
Line 79: img.Save(Server.MapPath("filename"))
Line 80: img.Dispose()
Line 81: ms.Close()


Source File: C:\Inetpub\ Line: 79

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
ImageRetreival.image.Page_Load(Object sender, EventArgs e) in C:\Inetpub\ System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
 
>>Server.MapPath("filename")

Server.MapPath is not an inbuilt method of all classes (it is availeble by default only to the classes that inherits Page class), however u could use the HttpContext object.

where exactly is this code placed???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top