dtqqq24248 2019-01-28 14:59
浏览 81

图像方向移动上传

I am implementing an image upload function to use the mobile phone camera. It is working fine, but the photos are always rotated wrong.

I did read about using the php function exif_read_data. I found codes how to use it and how to change the orientation and how to save it again. Now my problem is (using Android) that the exif_read_data array does not contain any "Orientation", so I am not able to change the orientation. I can not find any hints or posts about this problem. Why is my orientation not stored in this array?

Thanks for any help

  • 写回答

1条回答 默认 最新

  • dongtan8122 2019-01-28 15:29
    关注

    I ran into a similar problem a few weeks ago, the only solution I found was to rotate the image accordingly before setting it up on the View. No need to touch stuff related to orientation. Once I used this function, I uploaded my image to Firebase and everything was cool.

    public static Bitmap rotateBitmap(Bitmap sourceBitmap, float angle) {
        Matrix matrix = new Matrix();
        matrix.postRotate(angle);
        return Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);
    }
    

    Use this function to set it to your ImageView in this case:

    if (requestCode == Constants.REQUEST_CODE_CAMERA_PHOTO) {
                imgURL = data.getData();
                try {
                    Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imgURL);
                    bitmap = rotateBitmap(bitmap, -90);
                    ivProfile.setImageBitmap(bitmap);
    }
    

    I hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?