src/utils/convert.js
/**
* Detect subsampling in loaded image.
* In iOS, larger images than 2M pixels may be subsampled in rendering.
*/
Detect subsampling in loaded image.
In iOS, larger images than 2M pixels may be subsampled in rendering.
Detect subsampling in loaded image . In iOS larger images than 2M pixels may be subsampled in rendering .
function detectSubsampling(img) {
  var iw = img.naturalWidth, ih = img.naturalHeight;
  if (iw * ih > 1024 * 1024) { 
    var canvas = document.createElement('canvas');
    canvas.width = canvas.height = 1;
    var ctx = canvas.getContext('2d');
    ctx.drawImage(img, -iw + 1, 0);
    return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
  } else {
    return false;
  }
}
function detectSubsampling ( img ) { var iw = img . naturalWidth , ih = img . naturalHeight ; if ( iw * ih > 1024 * 1024 ) { var canvas = document . createElement ( 'canvas' ) ; canvas . width = canvas . height = 1 ; var ctx = canvas . getContext ( '2d' ) ; ctx . drawImage ( img , - iw + 1 , 0 ) ; return ctx . getImageData ( 0 , 0 , 1 , 1 ) . data [ 3 ] === 0 ; } else { return false ; } }
Detect subsampling in loaded image.
Detect subsampling in loaded image .
// subsampling may happen over megapixel image // subsampled image becomes half smaller in rendering size. // check alpha channel value to confirm image is covering edge pixel or not. // if alpha value is 0 image is not covering, hence subsampled.