Coder Social home page Coder Social logo

Comments (12)

 avatar commented on August 16, 2024 1

Ok, i researched the sources and found reason. The problem is that autoScale function is called twice - one time when we set width for canvas and second time when we set height. I fixed locally by removing this.autoScale() call from width and height setters and made this function public by adding it in Canvas.js:

(0, _webviewBinders.webviewMethods)(['toDataURL', 'autoScale'])

Then i set width and height of canvas in the following way:

this.canvas.width = 600;
this.canvas.height = 800;
this.canvas.autoScale();

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

It makes sense. To render in high resolution in IOS and Android react-native-canvas multiplies the canvas sizes by the device screen ratio so you must be using a device with a ratio of 2 and that's why you get an image two times larger than you expect.

Is this an issue for you? I think it's fixable but it won't be easy.

Hope that helps. Thanks for using react-native-canvas and reporting this issue.

from react-native-canvas.

 avatar commented on August 16, 2024

@iddan Hello again. Thank you for your quick response.

It seems final image is scaled 2 times than canvas size as you said. It's ok for me. But the problem is in another spot. By some reason canvas is resized in width and becomes 2 times bigger that leads to the following results:

This is how image looks in canvas:
screen shot 2017-11-30 at 2 24 51 pm

And this is final image after canvas.toDataURL() call:
screen shot 2017-11-30 at 2 29 29 pm

Could you point me how to fix that behaviour please?
Thanks in advance

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Cool, this is a good lead for a fix

from react-native-canvas.

spaceemotion avatar spaceemotion commented on August 16, 2024

Got the same problem today - "fixed" it by cropping the final image.
Any updates on when a fix is in sight? Cheers!

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Hey there. As I said before PRs are welcome. Currently I don't use this feature with a product and too busy to solve in my (non-existing) free time.

from react-native-canvas.

iegik avatar iegik commented on August 16, 2024
const handleCanvas = (canvas) => {
    const ctx = canvas.getContext('2d');
    ctx.fillStyle = 'purple';
    console.log(canvas.width, canvas.height)
    ctx.fillRect(0, 0, canvas.width, canvas.height);
};
...
<Canvas ref={handleCanvas} {...{width: 300, height: 400, style: {width: 300, height: 400}}}/>

On screenshot you can see, that size of rendered canvas did not match on iOS.

https://github.com/iddan/react-native-canvas/blob/master/src/Canvas.js#L13

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

The sizes of the canvas should be in IOS twice the actual size to make things complaint with retina. But if I understand correctly it doesn't behave like that on your device.

from react-native-canvas.

iegik avatar iegik commented on August 16, 2024

Yes, i think, it abut to boundaries of 300x150... default properties of webView?

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Yeah

from react-native-canvas.

mohammadFeiz avatar mohammadFeiz commented on August 16, 2024

hi , how can i set canvas width and height ? when i set canvas.width = 400 and canvas.height=600 in emulator nothing render and that will white screen

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Please open a new issue.

from react-native-canvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.