我正在做一个应用程序,我在那里检查图像大小,并对其进行比例计算,因为pdf中的高度必须始终为100px,宽度可以更改,我根据原始图片的比例更改它。
我试图将const变量导出到不同的组件。但它也给了我export { imageHeight };
和export { imageWidth };
的语法错误。如何在react native中进行此导入?这应该在react中起作用。我不能使用导出默认值,因为我已经有了它。
相机组件:
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,
})
-
您不能导出一个没有名称的JSON文件。
-
您不能在范围外使用let定义的变量
-
您可以使用
export default variableName
或export variableName
导出const {imageWidth, imageHeight} = Image.getSize(data.uri, (width, height) => { let imageWidth = width; let imageHeight = height; console.log(`The image dimensions are ${imageWidth}x${imageHeight}`); return {imageWidth, imageHeight} }, (error) => { console.error(`Couldn't get the image size: ${error.message}`); }); export imageHeight; export imageWidth;
和
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, })