javascript - Problems with asynchrony of loading images (using a canvas and timer) -
enter link description herei have seen derivatives of question ask here not think addresses problem.
i have canvas object , refreshing need be. many frames second.
to these new frames call web api within recurring timer latest time stamp of image on server , if different loads hidden canvas object data.
when loaded 'refreshes' visible canvas.
on observation have seen images can load out of sync. have tested order images sent server , have tested order images 'grabbed' server , displayed in client browser.
how can ensure initial image has finished loading before loading or skipping next image?
should use queue of canvas images , 'read' top 1? cause memory spike have read using queue in javascript can cause memory leak?
thanks
this javascript code:
i have misnised not inclduing html5 , error handling.
if not enough post rest...
<script type="text/javascript"> var j1 = new jpegimage(); j1.onload = function () { var d1 = ctx1.getimagedata(0, 0, 360, 238); j1.copytoimagedata(d1); //brightenandcontrastimage(d1, contrastby, brightenby); csingle.putimagedata(d1, 0, 0) }; var tmrfeeder; function startfeedup() { try { var throttled = _.delay(startnonhtml5feed, 100); } catch (err) { document.getelementbyid("divmode2").innerhtml = err; } } function startnonhtml5feed() { jquery(function ($) { jquery.support.cors = true; $.ajax({ crossdomain: true, type: "post", url: "feed.aspx/getnextframes", data: json.stringify({ alias: alias, guidlogon: guidlogon }), timeout: 10000, contenttype: "application/json; charset=utf-8", datatype: "json", success: function (msg) { var ts1 = msg.d['ts1']; if (ts1 == "") { ts1 = "0"; } if (t1 != ts1) { t1 = ts1; j1.load('/cloud/livexp.ashx?alias=' + alias + '&camindex=0&guid=' + ts1); } }); }); var throttled = _.delay(startnonhtml5feed, 100); } </script>
Comments
Post a Comment