English 中文(简体)
• 如何以智能创造形象
原标题:How to generate image with dart
  • 时间:2013-11-15 15:40:14
  •  标签:
  • dart

• 如何在服务器上用art子制造cha图?

i want generate random word image Validation .

who to use with dart lang?

lick jcaptcha and more lib.

使用html?

感谢很多人!

问题回答

我建议你使用“重建”模式“谷歌”。 这确实非常容易。 (见以下链接:https://developers.google.com/recaptcha/。) 命令在一部dart代码中使用二字节文字,您可使用联合图书馆(见)。

我用撰写了密码样本。 图书馆:

import  dart:math ;
import  package:image/image.dart ;

class Captcha {
  static final List<String> _randomChoice = [
     acdefhijkmnpqrstuvwxyz ,
     ABCDEFGHJKLMNPQRSTUVWXYZ ,
     234578 ,
  ];

  static final List<int> _choiceIndex = [0, 1, 2];

  static (Image, String) generate({
    int width = 250,
    int height = 75,
  }) {
    final image = Image(width: width, height: height);

    // background color
    fill(image, color: _bgColor());

    // add random character
    for (var x = 0; x < 40; x++) {
      final letterPool = _randomChoice[_choiceIndex[x % 3]];
      final letter = letterPool[random.nextInt(letterPool.length)];
      drawChar(
        image,
        letter,
        x: x % 10 * 25 + random.nextInt(21) - 5,
        y: (x ~/ 10) * 15 + random.nextInt(16) - 5,
        color: _lightColor(),
        font: arial14,
      );
    }

    // generate random captcha
    var index = _choiceIndex[random.nextInt(_choiceIndex.length)];
    final sb = StringBuffer();
    for (var item = 0; item < 5; item++) {
      final codePool = _randomChoice[_choiceIndex[index % 3]];
      final code = codePool[random.nextInt(codePool.length)];
      sb.write(code);

      drawChar(
        image,
        code,
        x: 30 + random.nextInt(16) - 5 + 40 * item,
        y: 10 + random.nextInt(16) - 5,
        color: _darkColor(),
        font: arial48,
      );
      index = index + 1;
    }

    // add some random lines
    for (var i = 0; i < 7; i++) {
      drawLine(
        image,
        x1: random.nextInt(width),
        y1: random.nextInt(height),
        x2: random.nextInt(width),
        y2: random.nextInt(height),
        color: _lightColor(175),
        thickness: 4,
      );
    }

    // add filter
    chromaticAberration(image, shift: 2);

    return (image, sb.toString().toLowerCase());
  }

  static final Random random = Random();

  static Color _darkColor([int a = 255]) {
    const minBrightness = 60;
    const randomNum = 40;
    final red = random.nextInt(randomNum) + minBrightness;
    final green = random.nextInt(randomNum) + minBrightness;
    final blue = random.nextInt(randomNum) + minBrightness;

    return ColorRgba8(red, green, blue, a);
  }

  static Color _lightColor([int a = 255]) {
    const maxBrightness = 160;
    const randomNum = 25;
    final red = random.nextInt(randomNum) + maxBrightness;
    final green = random.nextInt(randomNum) + maxBrightness;
    final blue = random.nextInt(randomNum) + maxBrightness;

    return ColorRgba8(red, green, blue, a);
  }

  static Color _bgColor() {
    final shuffled = [245, 245, 230]..shuffle();
    return ColorRgb8(
      shuffled[0] + random.nextInt(10),
      shuffled[1] + random.nextInt(10),
      shuffled[2] + random.nextInt(10),
    );
  }
}

// test code:
// main() async {
//   final (image, code) = Captcha.generate();
//   await encodePngFile( assets/test.png , image);
//   print(code);
// }

详情见





相关问题
Why my flutter app works in debug mode but not after release

I have read some other topics in stackovwrflow with similar problems, But none is answered. So I m asking here. I am developing an airhockey game using flutter in android studio. Everything is normal ...

DropdownButton Menu item width

is there any to reduce the width of the dropdownbutton menu widow width after clicking the dropdownbutton? only want to change the width of the window after clicking dropdownbutton and keeping the ...

• 如何设计我的闪闪lash屏

这正是我的闪lash屏幕是如何显示的,因此,我如何能够使标识填满四舍五入的圆环形,以及我能如何做到,这样我就能够增添一个背景形象。

Flutter App cannot be installed on Android TV

I m building a Flutter app that should support Android TV and Mobile devices. Despite Google Play shows that it is supported, I cannot install app on my MiBox device. While trying to install it, both ...

How to write to second tree in Firebase Realtime Database

I have a Firebase Realtime Database and I want to write to it, that s simple enough, but I have added more than one tree to my Database and want to know how to write to the second tree. Right now I ...

Moving the icon button to the right causes rendering issues

I am trying to align the icon button to the right of the Text field, I tried the row which made the icon button not centered vertically and now I am trying out the Stack widget. Here is my code - ...

热门标签