Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Returning an Image from a LabVIEW 7.1 Shared DLL to a calling .Net Application

Hi All,

I was wondering if anyone has been able to return an image from a LabVIEW 7.1 Shared DLL to the calling .Net Application. I can return the image data as one of the parameters from the exposed function but am unsure of what to do in the .Net Application to be able to use the image on an ASPX page.

I currently have a .Net Web Application calling a Web Service which calls a LabVIEW shared dll that produces images to disk and then it returns some XML data to the Web App(one piece of the XML is the image filename). I have created another Web Service that just returns the image. I should tell you that the Web Services and Web Apps are on separate boxes and LabVIEW is only on the Web Services box and that is something I can't change.

What I'd like to do is return the image at the same time I am returning the XML.

Any thoughts?

Thanks,

Jim
0 Kudos
Message 1 of 4
(3,974 Views)
In ASP.NET, you can not mix content types in the same response stream. Textual data and binary data, such as images, are sent to the client via separate requests to the web server. Therefore, there will be little that you can do with the image data in the ASPX. One option would be to save the image data in the ASP.NET cache and render the page with an HTML img element whose src attribute is a parameterized URL for an HTTP handler that will retrieve the image out of the cache and write it to the response stream. You could use a similar approach with your current system where the image is returned by a separate web service. For more information on using dynamic images in ASP.NET pages and custom HTTP handlers, see the discussion, links, and example code in this previous thread.

- Elton
0 Kudos
Message 2 of 4
(3,958 Views)
Hi Elton,

I totally understand the problem with the content type and ASP.Net. What I really need to know is that when I call a LabVIEW shared dll and have set up my function prototype to return "image data", how do I get access to that image data in .Net C# code where I called it from and turn it into an image.

Any ideas?

Jim
0 Kudos
Message 3 of 4
(3,951 Views)
What is the .NET data type for your image data that you're returning from your web service? A byte array? If so, you can recreate the image by creating a MemoryStream from the byte array, then creating the image by passing the stream to Image.FromStream. For example:


Image CreateImage(byte[] data)
{
if (data == null)
throw new ArgumentNullException("data");

Image img = null;
using (MemoryStream stream = new MemoryStream(data))
{
img = Image.FromStream(stream);
}

return img;
}


If the image data is not a byte array, how are you returning the image from your web service?

- Elton
Message 4 of 4
(3,946 Views)