Dans le cadre de la mise en place d'un control pour faire un Captcha, j'ai crée
CaptchaControl.vb:
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
 
Imports System.Drawing
Imports Microsoft.VisualBasic
Imports System.Drawing.Drawing2D
 
<DefaultProperty("MyCode"), ToolboxData("<{0}:CaptchaControl runat=server></{0}:CaptchaControl>")> _
Public Class CaptchaControl
    Inherits WebControl
 
    Dim _MyCode As String = Nothing
 
    <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property MyCode() As String
        Get
            If _MyCode = Nothing Then _MyCode = "Captach@"
            Return _MyCode
        End Get
 
        Set(ByVal Value As String)
            _MyCode = Value
        End Set
    End Property
 
    Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)
 
        Dim MyImg As New Web.UI.HtmlControls.HtmlImage
        MyImg.Attributes.Add("TITLE", _MyCode)
        'MyImg.Attributes.Add("SRC", BuildMyImg)
        MyImg.RenderControl(output)
 
    End Sub
 
    Protected Function BuildMyImg() As System.IO.MemoryStream
 
        Dim memSt As New System.IO.MemoryStream
 
        Dim b As New Bitmap(150, 30, Imaging.PixelFormat.Format32bppArgb)
        Dim gr As Graphics = Graphics.FromImage(b)
        Dim str As String = MyCode
 
        Dim sizeff As SizeF = gr.MeasureString(str, New Font("Arial", 25, FontStyle.Strikeout, GraphicsUnit.Pixel), 300)
        Dim hatchBrush As HatchBrush = New HatchBrush(HatchStyle.Wave, Color.DarkBlue, Color.Gray)
        gr.FillRectangle(hatchBrush, New Rectangle(0, 0, 150, 30))
        gr.DrawString(str, New Font("Arial", 15, FontStyle.Strikeout, GraphicsUnit.Point), Brushes.White, 5, 5)
        b.Save(memSt, Drawing.Imaging.ImageFormat.Jpeg)
        b.Dispose()
 
        Return memSt
 
    End Function
End Class

Mon problème est que je n'arrive pas à lier l'image bitmap de ma fonction BuildMyImg avec MyImg.Attributes.Add("SRC", BuildMyImg)
de RenderContents, j'ai essayé par aussi par tableau de byte ... et toujours sans succès.
J'ai regarder sur les forum et google (D'ailleur la constitution de l'image est reprise d'un script en httphandler de développez.com).

Je précise que le but de ce control est d'être extérieur à ma solution.
Je lui génère une chaine aléatoirement et il doit former le captcha à partir de cette chaine. Dans ma solution, je n'ai plus qu'à comparer ce que la personne à mis avec CaptchaControl.MyCode.

Je précise aussi que l'attribut "title" marche très bien. Quand je passe ma souris sur l'emplacement de l'image je vois bien s'afficher dans un infobulle la string générée. Par contre, à chaque essai, j'avais une croix rouge au lieu de mon image.

Quelqu'un peut-il m'aider?