使用 expo-image-picker 和 expo-image-manipulator 将 Android 上的图像上传到 Firebase 存储极差的图像质量

问题描述 投票:0回答:0

我正在尝试使用 expo-image-picker 和 expo-image-manipulator 将 Android 上的图像上传到 Firebase 存储,但是当它们上传到 Firebase 时,它们会出现极度像素化,并且颜色也很远。一切都在 iOS 和 Android 模拟器上运行良好。我不确定为什么只有物理 Android 设备有这个问题。这是我的代码:


 const handlePickImage = async () => {
    if (hasCameraRollPermission) {
      try {
        let result = await ImagePicker.launchImageLibraryAsync({
          mediaTypes: ImagePicker.MediaTypeOptions.Images,
          allowsEditing: true,
          aspect: [4, 3],
          quality: 1,
        });

        if (!result.cancelled) {
          handleUploadImage(result.uri);
        } else {
          alert(
            "Error"
          );
        }
      } catch (error) {
        console.log(error);
      }
    } else {
      alert("Please enable camera roll permissions in your settings.");
    }
  };



const handleUploadImage = async (uri) => {

    const resizedPhoto = await ImageManipulator.manipulateAsync(
      uri,
      [{ resize: { width: 750 } }],
      { }
    );

    const thumbnail = await ImageManipulator.manipulateAsync(
      uri,
      [{ resize: { width: 70, height: 70 } }],
      {}
    );

    const card = await ImageManipulator.manipulateAsync(
      uri,
      [{ resize: { width: 175, height: 170 } }],
      {}
    );

    const storage = getStorage();
    const uploadUri = `redacted`;
    const reference = ref(storage, uploadUri);

    const img = await fetch(resizedPhoto.uri);

    const bytes = await img.blob();

    const result = await uploadBytes(reference, bytes);

    const url = await getDownloadURL(result.ref);

我试过改变压缩率和质量,但没有成功。同样,这仅与物理 Android 设备有关。

android firebase react-native expo firebase-storage
© www.soinside.com 2019 - 2024. All rights reserved.