skip to Main Content

How to resize image using image_editor or any other library. I am used image library, but it gives error:

D/OpenGLRenderer: — Failed to create image decoder with message ‘unimplemented’

2

Answers


  1. Just a small tip: I would suggest including the code snippet to show exactly how you try to re-size, so others can explain why the error happens in the first place and help you do it the way you already started doing 🙏

    There are multiple ways to do it in Flutter and it is not super clear which exactly you might need (static sizes, dynamic fitting, resizing meaning compression or etc). I assume we talk about image resizing to the static size for its further rendering.

    One of them is simply using a ConstrainedBox as a parent widget on the Image.
    For example ⬇️, just use the path to your own asset instead of assets/vancouver.jpg and then tweak maxHeight and maxWidth if the sizes are static.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          home: const MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatelessWidget {
      const MyHomePage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: ConstrainedBox(
              constraints: const BoxConstraints(maxHeight: 200.0, maxWidth: 200.0),
              child: Image.asset("assets/vancouver.jpg"),
            ),
          ),
        );
      }
    }
    

    Hope it works for you!

    Login or Signup to reply.
  2. You can try https://pub.dev/packages/flutter_image_compress this package if you want to save file the small size image file.

    The below method of FlutterImageCompress package gives an another file according to your needs, you’ve to simply decrease the quality of your image file.

    Future<File> testCompressAndGetFile(File file, String targetPath) async {
    var result = await FlutterImageCompress.compressAndGetFile(
        file.absolute.path, targetPath,
        quality: 88,
        rotate: 180,
      );
    
    print(file.lengthSync());
    print(result.lengthSync());
    
    return result;
      }
    

    You can checkout other methods as well of this package that can help you to achieve your goal.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search