Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何使用flatter对图像进行像素化?_Flutter_Dart - Fatal编程技术网

Flutter 如何使用flatter对图像进行像素化?

Flutter 如何使用flatter对图像进行像素化?,flutter,dart,Flutter,Dart,我在屏幕上显示了一幅网络图像,想要应用块状像素效果,有人知道怎么做吗 有大量的LIB用于模糊或调整对比度/白平衡等,但似乎找不到任何东西来帮助我做其他图像效果 干杯我没有为自己努力,但我发现: 它只包含以下创建像素化图像的功能: Image pixelate(Image src, int blockSize, {PixelateMode mode = PixelateMode.upperLeft}) { if (blockSize <= 1) { return src

我在屏幕上显示了一幅网络图像,想要应用块状像素效果,有人知道怎么做吗

有大量的LIB用于模糊或调整对比度/白平衡等,但似乎找不到任何东西来帮助我做其他图像效果


干杯

我没有为自己努力,但我发现:

它只包含以下创建像素化图像的功能:

Image pixelate(Image src, int blockSize,
    {PixelateMode mode = PixelateMode.upperLeft}) {
  if (blockSize <= 1) {
    return src;
  }

  var bs = blockSize - 1;

  switch (mode) {
    case PixelateMode.upperLeft:
      for (var y = 0; y < src.height; y += blockSize) {
        for (var x = 0; x < src.width; x += blockSize) {
          if (src.boundsSafe(x, y)) {
            var c = src.getPixel(x, y);
            fillRect(src, x, y, x + bs, y + bs, c);
          }
        }
      }
      break;
    case PixelateMode.average:
      for (var y = 0; y < src.height; y += blockSize) {
        for (var x = 0; x < src.width; x += blockSize) {
          var a = 0;
          var r = 0;
          var g = 0;
          var b = 0;
          var total = 0;

          for (var cy = 0; cy < blockSize; ++cy) {
            for (var cx = 0; cx < blockSize; ++cx) {
              if (!src.boundsSafe(x + cx, y + cy)) {
                continue;
              }
              var c = src.getPixel(x + cx, y + cy);
              a += getAlpha(c);
              r += getRed(c);
              g += getGreen(c);
              b += getBlue(c);
              total++;
            }
          }

          if (total > 0) {
            var c = getColor(r ~/ total, g ~/ total, b ~/ total, a ~/ total);
            fillRect(src, x, y, x + bs, y + bs, c);
          }
        }
      }
      break;
  }

  return src;
}
图像像素化(图像src,int blockSize,
{PixelateMode=PixelateMode.upperLeft}){
如果(块大小0){
var c=getColor(r~/总数,g~/总数,b~/总数,a~/总数);
fillRect(src,x,y,x+bs,y+bs,c);
}
}
}
打破
}
返回src;
}

我没有亲自尝试,但我发现:

它只包含以下创建像素化图像的功能:

Image pixelate(Image src, int blockSize,
    {PixelateMode mode = PixelateMode.upperLeft}) {
  if (blockSize <= 1) {
    return src;
  }

  var bs = blockSize - 1;

  switch (mode) {
    case PixelateMode.upperLeft:
      for (var y = 0; y < src.height; y += blockSize) {
        for (var x = 0; x < src.width; x += blockSize) {
          if (src.boundsSafe(x, y)) {
            var c = src.getPixel(x, y);
            fillRect(src, x, y, x + bs, y + bs, c);
          }
        }
      }
      break;
    case PixelateMode.average:
      for (var y = 0; y < src.height; y += blockSize) {
        for (var x = 0; x < src.width; x += blockSize) {
          var a = 0;
          var r = 0;
          var g = 0;
          var b = 0;
          var total = 0;

          for (var cy = 0; cy < blockSize; ++cy) {
            for (var cx = 0; cx < blockSize; ++cx) {
              if (!src.boundsSafe(x + cx, y + cy)) {
                continue;
              }
              var c = src.getPixel(x + cx, y + cy);
              a += getAlpha(c);
              r += getRed(c);
              g += getGreen(c);
              b += getBlue(c);
              total++;
            }
          }

          if (total > 0) {
            var c = getColor(r ~/ total, g ~/ total, b ~/ total, a ~/ total);
            fillRect(src, x, y, x + bs, y + bs, c);
          }
        }
      }
      break;
  }

  return src;
}
图像像素化(图像src,int blockSize,
{PixelateMode=PixelateMode.upperLeft}){
如果(块大小0){
var c=getColor(r~/总数,g~/总数,b~/总数,a~/总数);
fillRect(src,x,y,x+bs,y+bs,c);
}
}
}
打破
}
返回src;
}