stomita/ios-imagefile-megapixel

Rendered object size not available

mikekay01 opened this issue · 1 comments

I am reading in an image file using
var mpImg = new MegaPixImage(file);

and then rendering the image to an tag using
var resImg = document.getElementById('testDummy');
mpImg.render(resImg, { maxWidth: 1000, maxHeight: 1000, quality: 1.0 });

Once the image is rendered to the "testDummy" image I am attempting to get the width and height of the image using
var w = $('#testDummy').width();
var h = $('#testDummy').height();

Unfortunately the height and width are 0 the first time I attempt to get the image, and the previous image size each subsequent time. I'm guessing there is some delay in the render function and I am attempting to get the value before the render is complete. Is there a way to get the rendered size once the image render is complete.

thanks.

Yes, rendering is asynchronous. You can use MegaPixImage#onrender to be notified when the rendering is done.

e.g.

var mpImg = new MegaPixImage(file);
mpImg.onrender = function() {
  var w = $('#testDummy').width();
  var h = $('#testDummy').height();
  alert('rendered width=' + w + ', height=' + h);
};
var resImg = document.getElementById('testDummy');
mpImg.render(resImg, { maxWidth: 1000, maxHeight: 1000, quality: 1.0 });