简单的验证码并制作不同的颜色

发布于 2024-11-18 12:02:38 字数 243 浏览 3 评论 0原文

我刚刚观看了链接 http://simplecaptcha.sourceforge.net/ ,它提供了一些演示图像显示验证码可以设计为彩色验证码,因此它不仅可以是黑白验证码。但由于某种原因,我找不到任何关于如何控制 SimpleCaptcha 颜色的教程:(如果您知道一些片段或教程,请分享它们。

感谢所有有用的评论:)

I've just watched the link as http://simplecaptcha.sourceforge.net/ and it gives demo of some images showing that captcha can be designed as a colored one so it can be not only black and white one. But for some reason I couldn't find any tutorials of how control SimpleCaptcha colors :( If you know some snippets or tutorials share them please.

All useful comments are appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我ぃ本無心為│何有愛 2024-11-25 12:02:38

您希望哪个部分是彩色的?例如,您可以通过 WordRenderer 控制文本的颜色。有关如何使用 Captcha.Builder 的示例,请访问在他们的网站。您可以将如下内容添加到任何这些示例中:

List<java.awt.Color> textColors = Arrays.asList(
     Color.BLACK, Color.BLUE, Color.RED);
List<java.awt.Font> textFonts = Arrays.asList(
     new Font("Arial", Font.BOLD, 40), 
     new Font("Courier", Font.BOLD, 40));

java.awt.Color backgroundColor = Color.ORANGE;

Captcha captcha = new Captcha.Builder(200, 50)
    .addText(
        new DefaultTextProducer(), 
        new DefaultWordRenderer(textColors, textFonts))
    .addBackground(new FlatColorBackgroundProducer(backgroundColor))
    .build();

DefaultWordRenderer 接受颜色和字体的List,以便您可以根据请求从多种颜色/字体中随机选择。因此,如果您只提供一种颜色和字体,那么您每次都会得到这些。如果您提供五种颜色和一种字体,那么您每次都会得到相同的字体,但颜色将从您提供的五种颜色中随机选择。

上面的示例使用 FlatColorBackgroundProducer,但还有其他选项,包括 GradiatedBackgroundProducerSquigglesBackgroundProducer

Which part do you want to be in color? You can, for example, control the color of the text via a WordRenderer. Examples of how to use their Captcha.Builder can be found on their website. You can add things like the following to any of these examples:

List<java.awt.Color> textColors = Arrays.asList(
     Color.BLACK, Color.BLUE, Color.RED);
List<java.awt.Font> textFonts = Arrays.asList(
     new Font("Arial", Font.BOLD, 40), 
     new Font("Courier", Font.BOLD, 40));

java.awt.Color backgroundColor = Color.ORANGE;

Captcha captcha = new Captcha.Builder(200, 50)
    .addText(
        new DefaultTextProducer(), 
        new DefaultWordRenderer(textColors, textFonts))
    .addBackground(new FlatColorBackgroundProducer(backgroundColor))
    .build();

DefaultWordRenderer accepts a List of colors and fonts so that you can pick from several colors/fonts randomly per request. So, if you provide it with only one color and font, then you'll get those every time. If you provide it with five colors and one font, then you'll get the same font every time, but the color will be selected randomly from the five that you provided.

The example above uses FlatColorBackgroundProducer, but there are other options, including GradiatedBackgroundProducer and SquigglesBackgroundProducer.

场罚期间 2024-11-25 12:02:38

可能使用类 ColoredEdgesWordRenderer。看看 http://simplecaptcha.sourceforge.net/javadocs/index.html

Probably using Class ColoredEdgesWordRenderer. Take look at http://simplecaptcha.sourceforge.net/javadocs/index.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文