The rest server returns an image stream.

Source: Internet
Author: User
Tags visual studio 2010

Assume that there is an image constantly changing at the backend of the rest server, and you want to provide a function to return the image stream, so that ASP. NET can be refreshed on a regular basis.

Rest server writes with Delphi Xe:

Function tremotediagnose. getviewpicturestream3 (aseesionid: string): tstream; <br/> begin <br/> result: = tmemorystream. create; <br/> try <br/> Inc (g_index); <br/> If (g_index mod 2) = 0 then <br/> tmemorystream (result ). loadfromfile ('C:/3s.png ') <br/> else <br/> tmemorystream (result ). loadfromfile ('C:/delphi-prism-mainlogo.png ') <br/> Reset T <br/> freeandnil (result); <br/> raise; <br/> end; <br/> end; </P> <p>

 

How can ASP. NET be displayed?

First, let's talk about Visual Studio 2010. I don't know what the previous version was like. This is really a huge memory-consuming tiger. I have 4 GB memory under windows7. After working for half a day, there will be insufficient memory, press Ctrl + C to display:

Check that the memory usage is 3.8gb.

 

To avoid refreshing the entire page, Ajax is required.

Assume that the web form has a webcontrols. Image component and sets its imageurl to myimage. aspx. The content of myimage. aspx is:

Write with Delphi Prism:

Namespace; </P> <p> interface </P> <p> uses <br/> system, <br/> system. data, <br/> system. configuration, <br/> system. web, <br/> system. web. security, <br/> system. web. sessionstate, <br/> system. web. UI, <br/> system. web. UI. webcontrols, <br/> system. web. UI. webcontrols. webparts, <br/> system. web. UI. htmlcontrols; </P> <p> type <br/> myimage = public partial class (system. web. UI. page) <br/> protected <br/> Method Page_load (Sender: object; E: eventargs); <br/> end; </P> <p> Implementation </P> <p> method myimage. page_load (Sender: object; E: eventargs); <br/> var <br/> MS: system. io. memorystream; <br/> O: tmyresult; <br/> S: string; <br/> vurl: string; <br/> VHC: remobjects. internetpack. HTTP. httpclient; <br/> vbytes: array of byte; <br/> vimage: image; <br/> vbmp: system. drawing. bitmap; <br/> FS: system. io. filestream; <br/> Vfilename: string; <br/> begin <br/> // you cannot use localhost ??!! <Br/> vurl: = 'HTTP: // 192.168.10.41: 8082/rest/restserver. dll/datasnap/rest/tremotediagnose/getviewpicturestream3/'; <br/> vurl: = vurl + system. uri. escapedatastring (Session. sessionid); <br/> VHC: = new remobjects. internetpack. HTTP. httpclient (); <br/> vbytes: = VHC. getbytes (vurl); <br/> // directly output the image <br/> response. clearcontent (); <br/> response. contenttype: = 'image/PNG '; <br/> response. binarywrite (vbytes); <br/> end; </P> <p> end. <br/>

Tick event of Ajax Timer:

VaR <br/> g_index: INTEGER: = 0; <br/> method _ default. timereffectick (Sender: system. object; E: system. eventargs); <br/> begin <br/> Inc (g_paramindex); <br/> image1.imageurl: = 'myimage. aspx? A = '+ g_paramindex.tostring (); <br/> end; <br/>

Here is a trick, that is, when you assign a value to image1.imageurl, the image will not be refreshed if the value remains the same. Therefore, you can give it a different parameter each time and let it think it has changed.

 

However, this effect is not satisfactory. Each time you refresh, there are two bad points:

1. the URL of the image will appear in the status bar, and the progress bar will also appear in the hour;

2. The mouse turns into an hourglass;

 

Can I solve this problem by using the server push method? How does image assign a byte stream to it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.