Comments (12)
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.
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.
@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:
And this is final image after canvas.toDataURL() call:
Could you point me how to fix that behaviour please?
Thanks in advance
from react-native-canvas.
Cool, this is a good lead for a fix
from react-native-canvas.
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.
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.
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.
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.
Yes, i think, it abut to boundaries of 300x150... default properties of webView?
from react-native-canvas.
Yeah
from react-native-canvas.
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.
Please open a new issue.
from react-native-canvas.
Related Issues (20)
- Please help.. HOT 1
- How to add rotate on a dom element like text HOT 1
- No license text HOT 5
- cropping an image HOT 1
- Not able to render image on ios 15.2.1 HOT 3
- Path2D differs from the Canvas API, in that it's not connected to a Canvas element HOT 2
- getcontext of a canvas gives TypeError: canvas.getContext is not a function HOT 2
- Difference in drawImage coordinates and getImageData/putImageData coordinates HOT 2
- why Why did I use getImageData() for more than 1 minute? HOT 2
- Canvas remain black on windows
- How do you get fillRect to occupy full dimensions? HOT 4
- ImageData/getImageData/putImageData strange behaviour HOT 2
- error HOT 2
- require cycle node_modules\react-native-canvas HOT 1
- canvas.loadFromJSON missing in react-native-canvas
- Error: Unable to resolve module ./CanvasRenderingContext2D HOT 1
- Not able to add fontFamily with font
- Application gets hang after 10 mins due to drawing on canvas continuously
- Can't draw image greater than 2048x2048 HOT 1
- Virtual/In-Memory Canvas HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-canvas.