Android:图像以 -90 旋转上传到 firebase

标签 android firebase firebase-storage android-bitmap

我正在使用三星 A52 用相机拍摄一些图像而不是我的 firebase 应用程序并保存它们,之后我会将这些图像上传到 firebase,我在上传之前压缩它们。

现在上传图片后我检查发现它们是 -90 旋转的,并不是所有的图片都旋转了,有些旋转了有些没有;

有什么想法吗?

或者在从 firebase 加载图像时是否有可能检测到它旋转到 retotate 是 90

从图库中获取图像后上传图像的功能。

for (uploadCount  = 0; uploadCount < ImageList.size(); uploadCount++) {
    String imagePath = productRef.child(UID).child("images").push().getKey();

    Uri IndividualImage = ImageList.get(uploadCount);
    assert imagePath != null;
    StorageReference ImageName = productImagesRef.child(UID).child(imagePath);
   

    //Compress Images
    Bitmap bmp = null;
    try {
        bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), IndividualImage);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    assert bmp != null;
    bmp.compress(Bitmap.CompressFormat.JPEG, 25, baos);
    byte[] data = baos.toByteArray();
    //End of compressing

    //start on uploading compressed
    ImageName.putBytes(data).addOnSuccessListener(taskSnapshot -> ImageName.getDownloadUrl()
            .addOnSuccessListener(uri -> {
                String url = String.valueOf(uri);
                StoreLink(url, imagePath);
            })).addOnProgressListener(snapshot1 -> {
        double progress = (100.0* snapshot1.getBytesTransferred()/snapshot1.getTotalByteCount());
        loadingDialog.setMessage("صورة رقم " + (count+ 1) + "  -->>   " +(int) progress + "%");
    });
}

最佳答案

所以我自己解决了它,这是我的解决方案:

我在 recyclerView item(Adapter) 的布局中添加了一个旋转按钮,然后创建了一个空的 ArrayList 来存储值或旋转度数。

我将 arraylist 传递给具有旋转按钮的适配器,现在当用户单击旋转时,90f 的值将保存到 arraylist,其位置如下:

imageRotation.set(holder.getAdapterPosition(), "90f");

因为 arrayList 可以采用 (index, value)

注意:如果 Arralist 位置没有现有值并且您跳过该位置以更改其他项目的旋转,它会崩溃。 为了解决这个问题,我做了一个 for 循环,以将 0f 作为旋转度填充 Arratlist。

for (int i = 0; i <= imageUriList.size(); i++) {
            imageRotation.add(i,"0f");
        }

然后当用户点击旋转时,它会更新位置值:

imageRotation.set(holder.getAdapterPosition(), "90f");

和上传 Activity 的onActivityResult:

我用过这个:

if (requestCode == LAUNCH_SECOND_ACTIVITY) {
            if (resultCode == Activity.RESULT_OK) {
                assert data != null;
                imageRotationArray = data.getStringArrayListExtra("imageRotationArray");
            }
        }

在压缩图像功能之前:

//创建新矩阵

                Matrix matrix = new Matrix();
                // setup rotation degree
                matrix.postRotate(Float.parseFloat(imageRotationArray.get(countRotateImage)));
                bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
                countRotateImage++;

关于Android:图像以 -90 旋转上传到 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70233266/

相关文章:

java - "No Instance of type variable R exist so that Observable conforms to Observable"更新到 RxJava2 时出错

java - CopyOnWriteArrayList 可以帮助允许从已放入迭代器的不同线程中删除项目

java - 无法解析方法 'subscribeon(io.reactivex.scheduler)'

java - 更新补丁更新后,三星 S10 设备的 Android12 中未收到 Firebase 推送通知

ios - 如何修复 : "fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)"

firebase - 如何限制组成员对文件的访问?

java - 如何在列表中存储不同类型的 JSON 对象?

Java 服务器 -- 使用 POST 发送 Push 到 google Firebase Cloud

android - 无法从 firebase 存储下载和实例化 3d 模型到统一

ios - 使用 uid 从 firebase 下载图像