[英]Error in using canvas.toDataURL() in react- native with npm react-native-canvas latest
[英]React-Native-Canvas Not Drawing Entire Rectangle
在制作另一個應用程序時,我遇到了react-native-canvas
的問題,所以我創建了這個最小的項目。 問題是 WebView 比 Canvas 小得多,並且沒有填滿整個 canvas。 這是代碼(與示例代碼非常相似):
import React, { Component } from 'react';
import { View } from "react-native"
import Canvas from 'react-native-canvas';
export default class App extends Component {
handleCanvas = (canvas) => {
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'purple';
ctx.fillRect(0, 0, 350, 700);
}
render() {
return (
<View style={{
width: 350,
height: 700
}}>
<Canvas ref={this.handleCanvas} style={{
width: 350,
height: 700,
borderWidth: 1,
borderColor: "red"
}} width={350} height={700} />
</View>
)
}
}
這是應用程序的屏幕截圖: 如您所見,應該將矩形渲染為 canvas(紅色輪廓)的完整大小的代碼沒有這樣做。 根據 Expo Inspect-Element 調試工具,WebView(即整個矩形)只有 300 x 150 像素。
我錯過了一些明顯的東西嗎? 或者這是react-native-canvas
的錯誤?
順便說一句,這是在 Android 上。
把它放在你的handleCanvas中:
canvas.width = 400;
canvas.height = 700;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.