You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:image/image.dart' as image_lib; import 'package:palette_generator/palette_generator.dart';
class ImageSplitter { List<Image> splitImage(Map<String, dynamic> mapData) { List<int> input = mapData['input']; int size = mapData['size']; image_lib.Image image = image_lib.decodeImage(input)!; int x = 0, y = 0; int width = (image.width / size).round(); int height = (image.height / size).round(); List<image_lib.Image> parts = []; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { parts.add(image_lib.copyCrop(image, x, y, width, height)); x += width; } x = 0; y += height; }
// convert image from image package to Image Widget to display
List<Image> output = []; for (var img in parts) { output.add(Image.memory(Uint8List.fromList(image_lib.encodeJpg(img)))); }
return output; }
Future<PaletteGenerator> getImagePalette(ImageProvider imageProvider) async { final paletteGenerator = await PaletteGenerator.fromImageProvider(imageProvider); return paletteGenerator; }
Future<List<Image>> runSplitterIsolate(List<int> input, int size) async { final Map<String, dynamic> data = { 'input': input, 'size': size, }; List<Image> splitImages = await compute(splitImage, data);
return splitImages; } }
|