I/flutter (17585): Error creating image: type ‘PixelUint8’ is not a subtype of type ‘int’ in type cast

late int alphaValue;
  late int redValue;
  late int greenValue;
  late int blueValue;

  int getAlpha(int pixel) {
    if (pixel is int) {
      return (pixel >> 24) & 0xFF;
    } else {
      // Gestione degli errori o valore di default nel caso in cui il valore di pixel non sia un intero
      return 0;
    }
  }

  int getRed(int pixel) {
    if (pixel is int) {
      return (pixel >> 16) & 0xFF;
    } else {
      // Gestione degli errori o valore di default
      return 0;
    }
  }

  int getGreen(int pixel) {
    if (pixel is int) {
      return (pixel >> 8) & 0xFF;
    } else {
      // Gestione degli errori o valore di default
      return 0;
    }
  }

  int getBlue(int pixel) {
    if (pixel is int) {
      return pixel & 0xFF;
    } else {
      // Gestione degli errori o valore di default
      return 0;
    }
  }



  Future<File> _createStartrail(List<File> images) async {
    if (images.isEmpty) {
      throw Exception('No images selected');
    }

    img.Image? startrailImage;

    for (final imageFile in images) {
      final bytes = await imageFile.readAsBytes();
      final image = img.decodeImage(Uint8List.fromList(bytes));

      if (image == null) continue;

      startrailImage ??= img.Image(width: image.width, height: image.height);

      for (int y = 0; y < image.height; y++) {
        for (int x = 0; x < image.width; x++) {
          final pixel = image.getPixel(x, y);

          alphaValue = getAlpha(pixel as int);
          redValue = getRed(pixel as int);
          greenValue = getGreen(pixel as int);
          blueValue = getBlue(pixel as int);

          final newPixel = (alphaValue << 24) | (redValue << 16) | (greenValue << 8) | blueValue;

          startrailImage.setPixel(x, y, newPixel as img.Color);
        }
      }
    }

    final output = await getTemporaryDirectory();
    final outputPath = '${output.path}/startrail.png';

    final outputFile = File(outputPath);
    await outputFile.writeAsBytes(img.encodePng(startrailImage!));

    return outputFile;
  }








  // Aggiungi una variabile per tenere traccia dell'immagine sommata
  File? _combinedImage;

// Aggiungi un metodo per combinare le immagini e mostrare l'anteprima
  void _combineImages() {
    if (_images.isNotEmpty) {
      _createStartrail(_images).then((combinedImage) {
        setState(() {
          _combinedImage = combinedImage;
        });
      }).catchError((error) {
        // Gestione degli errori in caso di fallimento della creazione dell'immagine
        print('Errore durante la creazione dell'immagine startrail: $error');
      });
    }
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Camera Preview')),
      body: Column(
        children: [
          Expanded(
            child: FutureBuilder<void>(
              future: _initializeControllerFuture,
              builder: (context, snapshot) {
                if (snapshot.connectionState == ConnectionState.done) {
                  return AspectRatio(
                    aspectRatio: 16 / 9,
                    child: CameraPreview(_controller),
                  );
                } else {
                  return const Center(child: CircularProgressIndicator());
                }
              },
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: _pickImages,
                child: const Text('Select Images'),
              ),
              const SizedBox(width: 10),
              ElevatedButton(
                onPressed: _combineImages, // Combinare le immagini quando si preme il pulsante
                child: const Text('Create Startrail'),
              ),
            ],
          ),
          if (_imagePreviews.isNotEmpty)
            Container(
              padding: EdgeInsets.symmetric(vertical: 10),
              height: 100,
              child: ListView(
                scrollDirection: Axis.horizontal,
                children: _imagePreviews,
              ),
            ),
          if (_combinedImage != null)
            Container(
              padding: EdgeInsets.all(10),
              child: Image.file(_combinedImage!),
            ),
        ],
      ),
    );
  }
}xt`

Hi guys I’m creating an app with Dart and Flutter. I select the images from the gallery and put them on the screen (up to this point the app works), when I go to add the images together I get this error

I/flutter (17585): Error creating image: type ‘PixelUint8’ is not a subtype of type ‘int’ in type cast

New contributor

Gabriele Iocco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật