【问题标题】:Android app sends pictures to web server and pictures rotateAndroid 应用程序将图片发送到 Web 服务器并旋转图片
【发布时间】:2014-02-10 10:32:18
【问题描述】:

我正在制作一个 android 应用程序,它可以发送用户明确拍摄的图片并将其发送到 Web 服务器。接下来,我在 Web 应用程序中显示这些图片。

但是,从智能手机拍摄的纵向照片会在服务器中旋转显示,就好像它们是在横向模式下拍摄的一样,反之亦然。

知道为什么会这样吗?

【问题讨论】:

标签: android html image web-applications webserver


【解决方案1】:

图像有一个属性,“exif 标签”。它讲述了图像的方向。您可以在将图像发送到服务器之前检查此标记的值。

您可以使用以下方法获取未旋转的图像

public final static Bitmap getUnRotatedImage(String imahePath, Bitmap rotattedBitmap)
    {
        int rotate = 0;
        try
        {
            File imageFile = new File(imahePath);
            ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
            int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

            switch (orientation)
            {
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
        Matrix matrix = new Matrix();
        matrix.postRotate(rotate);
        return Bitmap.createBitmap(rotattedBitmap, 0, 0, rotattedBitmap.getWidth(), rotattedBitmap.getHeight(), matrix,
                true);
    }

它有两个参数,图像路径和位图图像。

在将图像发送到服务器之前尝试此方法。

【讨论】:

    猜你喜欢
    • 2011-07-21
    • 1970-01-01
    • 2012-12-23
    • 2018-09-03
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多