图像到RGB矩阵的抖动



我是一个初学者。我想从我的本地选择一个图像,并将其转换为RGB数组。谁能给我提供正确的代码?

你可以使用这个包- image

它提供了图像转换和操作实用功能。

import 'package:image/image.dart' as Imagi;

下面是如何使用它从ImagePicker()获取文件的RGB矩阵-

final image = await ImagePicker().pickImage(source: ImageSource.gallery);
if (image == null) return;
final imageTemp = File(image.path);
controlImage = imageTemp;

现在这里有一个函数用于获得RGB矩阵-

List<List<int>> imgArray = [];
void readImage() async{
final bytes = await controlImage!.readAsBytes();
final decoder = Imagi.JpegDecoder();
final decodedImg = decoder.decodeImage(bytes);
final decodedBytes = decodedImg!.getBytes(format: Imagi.Format.rgb);
// print(decodedBytes);
print(decodedBytes.length);
// int loopLimit = decodedImg.width;
int loopLimit =1000;
for(int x = 0; x < loopLimit; x++) {
int red = decodedBytes[decodedImg.width*3 + x*3];
int green = decodedBytes[decodedImg.width*3 + x*3 + 1];
int blue = decodedBytes[decodedImg.width*3 + x*3 + 2];
imgArray.add([red, green, blue]);
}
print(imgArray);
}

数组imgArray将包含RGB矩阵

最新更新