Size of Canvas / panel different from the Bitmap ?

Hubert Brandel

Active Member
Licensed User
Longtime User
Hi,

i found the signature capture example from here and it is fine, but I need a little bit more ;-)

I need a bitmap with the signature of 100x160 pixel (to be compatible with the PALM and Windows Mobile Version of the program.
On Windows Mobile or Palm it was signed with a small pen, so it works.
The data is then coded (translated) in a array of bytes ().

Android needs more space to sign with a finger :sign0137:

So I think about using 4 pixel in canvas/panel converted to 1 in Bitmap.
Pen with 4 or 5 Pixels ...

Panel/View 400x640 on a activity (480x800) in landscape mode.
Writing the Touch as a pixel in a bitmap with 100x160 connected with the panel ...

Is this possible ?

If not, Is it possible to shrink a bitmap from 400x640 to 100x160 ?
I can't find a method in the bitmap class .
 

klaus

Expert
Licensed User
Longtime User
Hi Hubert,
Yes it's possible.
Attached a small test program.
The user signs in the big yellow rectangle, simultanusly the real size is also shown on top.
Clicking on OK copies the real bitmap.
You can play with the Stroke value to set the line thickness of the real bitmap.
B4X:
Sub Globals
    Dim x00, y00, x01, y01 As Float
    Dim x10, y10, x11, y11 As Float

    Dim pnlSignature, pnlBitmap As Panel
    Dim cvsSignature, cvsBitmap As Canvas
    Dim btnOK As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim x, y As Float
    
    btnOK.Initialize("btnOK")
    Activity.AddView(btnOK, 10, 10, 100, 60)
    btnOK.Text = "OK"
    
    pnlSignature.Initialize("pnlSignature")
    Activity.AddView(pnlSignature, 80, 80, 640, 400)
    pnlSignature.Color = Colors.Yellow
    cvsSignature.Initialize(pnlSignature)
    
    pnlBitmap.Initialize("")
    Activity.AddView(pnlBitmap, 320, 0, 160, 100)
    pnlBitmap.Color = Colors.White
    cvsBitmap.Initialize(pnlBitmap)
End Sub

Sub pnlSignature_Touch (Action As Int, X As Float, Y As Float) As Boolean
    
    Stroke = 2
    Select Action
    Case Activity.ACTION_DOWN
        x00 = X
        y00 = Y
        x10 = Max(Stroke, X / 4)        ' garanties at least one Stroke
        y10 = Max(Stroke, Y / 4)
    Case Activity.ACTION_MOVE
        x01 = X
        y01 = Y
        x11 = Max(Stroke, X / 4)
        y11 = Max(Stroke, Y / 4)
        Log(x00&" "&x01&" "&y00&" "&y01)
        cvsSignature.DrawLine(x00, y00, x01, y01, Colors.Black, 4)
        cvsBitmap.DrawLine(x10, y10, x11, y11, Colors.Black, Stroke)
        x00 = x01
        y00 = y01
        x10 = x11
        y10 = y11
        pnlSignature.Invalidate
        pnlBitmap.Invalidate
    End Select
    Return True
End Sub

Sub btnOK_Click
    Dim bdr As BitmapDrawable
    Dim bmp As Bitmap
    Dim destRect As Rect
    
    destRect.Initialize(0, 0, 160, 100)
    bdr = pnlBitmap.Background
    bmp = bdr.Bitmap
    cvsSignature.DrawBitmap(bmp,Null,destRect)
    pnlSignature.Invalidate
End Sub
Best regards.
 

Attachments

  • Signature.zip
    5.8 KB · Views: 264
  • Signature.jpg
    Signature.jpg
    26.9 KB · Views: 256
Upvote 0
Top