Sort of a small issue here that I've been struggling to find an answer to.
I am using the ios native camera to take a photo which I am then sending to phonegap to run some javascript on.
I pass the image into javascript, then draw it onto the left side of a small canvas element I have prepared in which the right side I will produce an altered image of the original (a side by side comparison). I realize that the images between the iphone4 and the iphone4s are differently sized pixel-wise but are at least the same proportion. My draw code:
function imageLoaded(img, frontCamera) {
element = document.getElementById("canvas1");
c = element.getContext("2d");
// read the width and height of the canvas- scaled down
width = element.width; //188 94x2
height = element.height; //125
//used for side by side comparison of images
w2 = width / 2;
// stamp the image on the left of the canvas
if (frontCamera) {
c.drawImage(img, 0, 0, 94, 125);} else{
c.drawImage(img, 0, 0, 94, 125)}
// get all canvas pixel data
imageData = c.getImageData(0, 0, width, height);
//more stuff here
}
When I execute this code on an iphone4, the image appears as should, side by side with the corrected image. When I use an iphone4s, the image draws out with the correct width, but it is a super squashed image, occupying the top sliver of the canvas.
Both devices are registering a screen.height and screen.width of 480 and 320 respectively with a window.devicePixelRatio of 2.
I figured the drawImage function would inherently scale the image appropriately.
I cannot seem to figure out what I am doing wrong. Thanks for the help!