Android Question How to load an image in a canvas?

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I am using "SignatureCapture" and I need in some cases to load/show the signature if it has already been entered before.

I have edited SignatureCapture.bas and added this:

B4X:
Sub Load(SD As SignatureData, Dir As String, Name As String)
    Dim ent As InputStream
    ent = File.OpenInput(Dir,Name)   
    Dim bmp As Bitmap
    bmp.InitializeMutable(SD.Panel.Width,SD.Panel.Height)   
    SD.Canvas.Initialize2( bmp )
    ent.Close   
End Sub

I don't know if this is correct.
Then I don't know how to use it from my application. It doesn't show anything.

B4X:
Sub btPedirFirma_Click
    CanvasFirma.Initialize(pnFirma)

    If Not (SD.IsInitialized) Then
        SD.Initialize
    End If

    SD.Canvas = CanvasFirma
    SD.Panel = pnFirma
    SD.SignatureColor = Colors.Blue
    SD.SignatureWidth = 3dip

    If File.Exists(cDirFirmas,cFileFirma) Then
        SignatureCapture.Load(SD, cDirFirmas, cFileFirma)
        pnFirma.Invalidate
    End If
End Sub

Can you advise me?
Thank you.
 

vecino

Well-Known Member
Licensed User
Longtime User
Thank you, friends, I don't think I have explained myself well.
I have signature capture implemented, no problem with that.
But what I need is to load the signature if you have already signed before.
I mean, the client signs and the same is saved, perfect.
But sometimes the customer finally decides to add some more products to his purchase, or remove some, and then the rectangle must appear again for him to sign, and in this case, what I want is to show/load the signature he made before.
The problem is that I don't know how to load that signature in the canvas.
The 2 options that you have indicated me does not have the possibility to load the signature, it only has the option to save it.
Thanks again.

I have been using this one for many years:
https://www.b4x.com/android/forum/threads/signature-capture-tutorial.9096/

I added the "Load" method, but it doesn't work, that's what I'm asking.
Thanks again.

B4X:
'Code module
Sub Process_Globals
    Dim px, py As Int
    Type SignatureData (Canvas As Canvas, Panel As Panel, SignatureColor As Int, SignatureWidth As Int)
End Sub

Sub Panel_Touch(SD As SignatureData, x As Int,y As Int, Action As Int)
    If Action = 0 Then 'mouse down constant
        px = x
        py = y
    Else
        SD.Canvas.DrawLine(px, py, x, y, SD.SignatureColor, SD.SignatureWidth)
        SD.Panel.Invalidate
        px = x
        py = y
    End If
End Sub

Sub Clear(SD As SignatureData)
    SD.Canvas.DrawColor(Colors.White)   
    SD.Panel.Invalidate
End Sub

Sub Save(SD As SignatureData, Dir As String, Name As String)
    Dim out As OutputStream
    out = File.OpenOutput(Dir, Name, False)
    SD.Canvas.Bitmap.WriteToStream(out, 100, "PNG")
    out.Close
End Sub

' (Vecino)  Carga la firma realizada anteriormente por el cliente.
Sub Load(SD As SignatureData, Dir As String, Name As String)
    Dim ent As InputStream
    ent = File.OpenInput(Dir,Name)   
    Dim bmp As Bitmap
    bmp.InitializeMutable(SD.Panel.Width,SD.Panel.Height)   
    SD.Canvas.Initialize2( bmp )
    ent.Close   
End Sub
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Then I guess you should initialize again the canvas with the file you saved.
But, if the client changes the purchased products, should not him sign again?



1625556413403.png
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Yes, he should sign, but the client wants the signature to be shown if he signed before, and the end client to accept it or to erase it and sign again. You know, sometimes they make requests that have no logic.
Thank you very much.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
See:
B4X:
Sub Panel_Touch(SD As SignatureData, x As Int,y As Int, Action As Int)
    If Action = 0 Then 'mouse down constant
        px = x
        py = y
    Else
        SD.Canvas.DrawLine(px, py, x, y, SD.SignatureColor, SD.SignatureWidth)
        SD.Panel.Invalidate
        px = x
        py = y
    End If
End Sub

B4X:
SD.Canvas.DrawLine(px, py, x, y, SD.SignatureColor, SD.SignatureWidth)
SD.Canvas.DrawCircle(x, y, SD.SignatureWidth/2, SD.SignatureColor, True, SD.SignatureWidth/2)

1625583164548.png
 
Last edited:
Upvote 0
Top