PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 5, 2022

[FIXED] How to convert CameraController's XFile to Image type in Flutter?

 May 05, 2022     camera, dart, flutter, image     No comments   

Issue

Flutter's CameraController has a takePicture() method for taking picture from the camera which gives type of Future<XFile>, so I need to convert it to Image type from package:image/image.dart package to manually crop it with another method.

How to convert it?


Solution

This is my found solution:

import 'dart:io';
import 'package:image/image.dart' as img;

...

CameraController _controller;

...

final xFile = await _controller.takePicture();
final path = xFile.path;
final bytes = await File(path).readAsBytes();
final img.Image image = img.decodeImage(bytes);



Answered By - Mohsen Emami
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing