meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation
http://camanjs.com
BSD 3-Clause "New" or "Revised" License
3.56k stars 406 forks source link

camanJS not working in android #99

Open ShreenivasCh opened 11 years ago

ShreenivasCh commented 11 years ago

CamanJs effects are not working on android mobile... why????????

myjangle commented 11 years ago

how are you trying to use the effects on the android mobile phone?

ghost commented 11 years ago

if I use existing canvas of an image like this: Caman(clone[0], function () { //clone is jquery of the canvas in the DOM this.render(); }); it will show a blank image on android emulator but it will works good on desktop browser (Chrome). I did a little bit of debug to Caman and I found in the function "Caman.prototype.hiDPIAdjustments" the ratio is 1 in chrome and 2 in android, this is because "window.devicePixelRatio" return 2 in android instead of 1. therefore, it makes the canvas to show a blank image.

hope It will help you.

Additional things: after removing this piece of code for caman: if (ratio !== 1) { Log.debug("HiDPI ratio = " + ratio); this.scaled = true; this.originalWidth = this.canvas.width; this.originalHeight = this.canvas.height; this.canvas.width = this.originalWidth * ratio; this.canvas.height = this.originalHeight * ratio; this.canvas.style.width = "" + this.originalWidth + "px"; this.canvas.style.height = "" + this.originalHeight + "px"; this.context.scale(ratio, ratio); this.width = this.canvas.width; return this.height = this.canvas.height; }

This is the code that makes the problem and it will get into the if statement if ratio is not 1 (the same value to talk about above). if I remove this piece of code it works good, but it not the way to solve the problem and I can not fix the bug because I don't really understand way this statement here from the first place.

das-akeem commented 10 years ago

good point noampz! i solved my android problems by adding simply "data-caman-hidpi-disabled" to my canvas like stated in http://camanjs.com/guides/#BasicUsage. works like a charm now ;)

kaheidt commented 10 years ago

I have this same problem on both Android and iPhones, and I'd rather not disable hidpi display if the device supports it (which I believe iPhones are supposed to). Is there a solution for the iPhone that will allow me to still use HiDPI/Retina?