Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 从uri获取高度和宽度_React Native_React Native Android - Fatal编程技术网

React native 从uri获取高度和宽度

React native 从uri获取高度和宽度,react-native,react-native-android,React Native,React Native Android,我有一个应用程序,可以拍摄照片并将其添加到pdf文件中。问题是调整大小。我可以用像素调整它的大小,但不能保持原来的比例。我需要原始的高度和宽度来计算正确的尺寸 计算:将高度除以宽度,例如1200/1600=0,75。然后我们可以调整pd图像高度100px,宽度为100/0,75 问题是:如何获得图像的大小(data.uri) 我的代码: takePicture = async() => { if (this.camera) { const options

我有一个应用程序,可以拍摄照片并将其添加到pdf文件中。问题是调整大小。我可以用像素调整它的大小,但不能保持原来的比例。我需要原始的高度和宽度来计算正确的尺寸

计算:将高度除以宽度,例如1200/1600=0,75。然后我们可以调整pd图像高度100px,宽度为100/0,75

问题是:如何获得图像的大小
(data.uri)

我的代码:

takePicture = async() => {
    
    if (this.camera) {
        const options = { quality: 0.5, base64: true , fixOrientation: true}; // Option for wuality etc
        const data = await this.camera.takePictureAsync(options); // Take the image
        console.log(data.uri); // Prints image (data) address to console log
        back(data.uri) // Go back to ReportFault page
    }
  };

您可以使用react native
Image
getSize方法

试试这个

import { Image } from 'react-native';

.....

Image.getSize(uri, (width, height) => {
  console.log(`The image dimensions are ${width}x${height}`);
}, (error) => {
  console.error(`Couldn't get the image size: ${error.message}`);
});

谢谢你Mehran,现在它工作了。今天我会在6个小时内找到解决方案。我头疼,真的。谢谢
import { Image } from 'react-native';

.....

Image.getSize(uri, (width, height) => {
  console.log(`The image dimensions are ${width}x${height}`);
}, (error) => {
  console.error(`Couldn't get the image size: ${error.message}`);
});