【发布时间】:2020-11-25 10:55:35
【问题描述】:
我正在做应用程序,我检查图像大小,计算它的比例,因为 pdf 中的高度必须始终为 100px,宽度可以更改,我将其更改为原始图片的比例。
我试图将 const 变量导出到不同的组件。但它也给了我export { imageHeight }; 和export { imageWidth }; 的语法错误。如何在 react-native 中进行此导入?这应该在反应中起作用。我不能使用导出默认值,因为我已经有了它。
相机组件:
Image.getSize(data.uri, (width, height) => { // KOODI TOIMII ja hakee tiedot
let imageWidth = width;
let imageHeight = height;
console.log(`The image dimensions are ${imageWidth}x${imageHeight}`);
}, (error) => {
console.error(`Couldn't get the image size: ${error.message}`);
});
export { imageHeight };
export { imageWidth};
然后,我有一个 pdf 创建组件:
import { imageHeight, imageWidth } from './Camera';
const pdfHeight = 100;
const ratio = imageHeight/imageWidth; // example 1200/1600=0,75
page.drawImage(arr[i].path.substring(7),'jpg',{
x: imgX,
y: imgY,
width: pdfHeight/ratio,
height: pdfHeight,
})
【问题讨论】:
-
嗨@Joko Joko,对此有一个旧答案。看看它stackoverflow.com/questions/49280777/…。这将解决您的问题
标签: react-native