【问题标题】:How to check the quality of image in react native like if I want to take 60%. Quality image so how to get it如果我想占 60%,如何检查 React Native 中的图像质量?质量图像,所以如何得到它
【发布时间】:2023-01-30 14:48:50
【问题描述】:

如果我想占 60%,如何检查 React Native 中的图像质量?质量图像,所以如何得到它

我通过像素分辨率进行了尝试,但没有用

【问题讨论】:

    标签: reactjs react-native native


    【解决方案1】:

    如果您使用react-native-image-picker 上传图片,您可以在选项中设置maxWidth、maxHeight 或图片质量来减小尺寸。

    const options = {
        title: 'Select Picture',
        storageOptions: {
            skipBackup: true,
            path: 'images',
        },
        maxWidth: 500,
        maxHeight: 500,
        quality: 0.5,
    };
    

    或者,如果您想适合任何 View 中的图像,您可以使用 ImageresizeMode 属性,其类型为 enum('cover', 'contain', 'stretch', 'repeat', 'center')

    【讨论】:

      【解决方案2】:

      您可以使用 react-native-image-picker 库,并可以限制用户上传的图像质量,您可以根据您的要求编辑其余参数。

      const result = await ImagePicker.launchImageLibraryAsync({
          mediaTypes: "Images",
          allowsEditing: true,
          base64: true,
          quality: 0.6,
      });
      
      if (!result.cancelled) {
          const fileSize = result.base64.length * (3 / 4) - 2;
          if (fileSize > 6000000) {
              setFileSizeError(true);
          } else {
              setFileSizeError(false);
              const base64 = `data:image/png;base64,${result.base64}`;
              await dispatch(myExampleAction(base64));
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-06-28
        • 2012-06-18
        • 2010-10-08
        • 1970-01-01
        • 2019-09-19
        • 1970-01-01
        • 2011-08-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多