Flutter自动旋转照片

时间:2019-06-29 14:45:51

标签: flutter dart

我正在开发 Flutter 应用程序,并且使用 image_picker 处理相机/画廊。我使用image_picker ^ 0.6.0 + 10

这是我用来拍照或从画廊中挑选图像的代码。

File _imageFile;

void _getImage(BuildContext context, ImageSource source) {
  ImagePicker.pickImage(
    source: source,
  ).then((File image) {
    setState(() {
      _imageFile = image;
    });
    Navigator.pop(context);
  });
}

void _openImagePicker(BuildContext context) {
  showModalBottomSheet(
    context: context,
    builder: (BuildContext context) {
      return Container(
        height: 150.0,
        padding: EdgeInsets.all(10.0),
        child: Column(children: [
          Text(
            'Pick an Image',
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
          SizedBox(
            height: 10.0,
          ),
          FlatButton(
            textColor: Theme.of(context).primaryColor,
            child: Text('Use Camera'),
            onPressed: () {
              _getImage(context, ImageSource.camera);
            },
          ),
          FlatButton(
            textColor: Theme.of(context).primaryColor,
            child: Text('Use Gallery'),
            onPressed: () {
              _getImage(context, ImageSource.gallery);
            },
          )
        ]),
      );
    },
  );
}

我使用以下代码预览所选图像:

Image.file(
  _imageFile,
  fit: BoxFit.cover,
  height: 200.0,
  width: MediaQuery.of(context).size.width,
  alignment: Alignment.topCenter,
);

问题:每次我拍照时,照片在预览中都会旋转90度。当我拍摄照片时,它也会在相机中旋转(请参阅下面的附件照片)。如果使用图库,则图像不会旋转。然后,我将此图像发送到服务器,但仍在其中旋转。

带有屏幕截图的示例:

Before taking photo

After taking photo

0 个答案:

没有答案
相关问题