【问题标题】:Android: Images uploaded to firebase with -90 rotationAndroid:图片以 -90 度旋转上传到 Firebase
【发布时间】:2023-03-23 03:06:01
【问题描述】:

我正在使用三星 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 + "%");
    });
}

【问题讨论】:

    标签: android firebase firebase-storage android-bitmap


    【解决方案1】:

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

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

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

    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++;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-11
      • 2012-04-06
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多