0

Is it possible to compress without saving in files images from API to resize image?

I found one of packages which is doing this job - flutter_native_image: ^0.0.6 but all of these packages works onle if I am going to pick uup images from file storage and after that to reduce size to dowload it to my app.

So can I reduce image weight? Now it is 2MB images which comes from API.

I was trying this thing:

 if (hubConnection.state == HubConnectionState.Connected) {
      await hubConnection.invoke('GetImage', args: [carId]).then((value) {
        carImage = value as String;
      });
      var compressed = await FlutterNativeImage.compressImage(carImage ?? '',
          quality: 50, percentage: 30);
      print(compressed);
      print('is it compressed?');
    }

But it gives me an error: '[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(file does not exist, iVBORw0KGgoAAAANSUhEUgAAB4AAAAQ4CAIAAABnsVYUAAAgAElEQVR4AXzBi65tWZqd1e/rY659TkRmpatsGXFHyI+BQOJJAPHkIHGxJVOUMzMizl5z/J2xduQ+kVUUtOaP/+N/90V3+x+4mA0XRxdHw1F'

I understood it says about my carImage variable is not File type, but Base64 type, so if there is any chance to make image size smaller without reaching out backend devs?

inkwelll075
  • 494
  • 4
  • 19
  • 1
    Did you try https://pub.dev/packages/flutter_image_compress package? You need just convert `String` to `Uint8List` then call `FlutterImageCompress.compressWithList(uint8list_var, quality)` Here you can see convert string to uint8list https://stackoverflow.com/questions/51613234/convert-a-string-of-uint8list-to-a-unit8list – Reza M Nov 21 '22 at 08:16
  • I ended up using flutter_image_compress: ^1.1.3, thanks to @RezaM for advise. Also I was trying to check my theory about making workload faster if I will be using images compressor in my app. So it compress greatly, but load from server isn't getting any faster t and still the same (I am getting about 50 photos from API and it has 2MB size which is pretty big) – inkwelll075 Nov 21 '22 at 10:40

0 Answers0