bitmap and finger move

derez

Expert
Licensed User
Longtime User
1. How do I create a bitmap which is a copy of a rectangle from another bitmap ? there are 3 options to initialize but not that one.

2. How do I implement "mouse" move - identify the finger touch on the activity and get the x y while it moves ?
 
Last edited:

derez

Expert
Licensed User
Longtime User
Thanks :)
The touch works already (slowly and jumpy on the emulator...)
The canvas is a treasure of methods !
 

derez

Expert
Licensed User
Longtime User
Something is missing :( , see the error photo.

shouldn't the dest rect be defined with reference to the target (in this case - the activity), other wise how to draw on another bitmap ?
edit: found the answer to the drawing on bitmap - by the canvas initialize2, but the error is still unclear.
edit : found that one too - the canvas wasn't initialized. now i'm happy.
 

Attachments

  • bitmaperror.jpg
    bitmaperror.jpg
    89.6 KB · Views: 314
Last edited:

derez

Expert
Licensed User
Longtime User
how can I copy part of a bitmap to another bitmap ? Using canvas - it draws only on a view.

The Jpeg library by Agraham enabled to copy part of a bitmap directly from a file, it will be good to have it here also.
 
Last edited:

derez

Expert
Licensed User
Longtime User
Thank you. I wanted to use an imageview but couldn't get its image...
Now I hope I'll manage.
 

derez

Expert
Licensed User
Longtime User
File doesn't include anything on writing text to a file, after opening it, only reading, and only the whole file. How do I read a line, and write a line ?
 

derez

Expert
Licensed User
Longtime User
Erel

You can get the bitmap that the canvas draws on with canvas.Bitmap.
This means that you use the view only as a bitmap container.

initializing a canvas on a view (not activity) raises an error - "width and height must be >0". I tried both imageview and a button, defined by the designer or added by code, and the size is 580x580.
Can you check please ?
 

Attachments

  • canvas.jpg
    canvas.jpg
    68.6 KB · Views: 256
Last edited:

derez

Expert
Licensed User
Longtime User
Thank you.
now this - how do I initialize a stream ? I declared the object but there is no method for initializing it.

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
Dim tb1 As EditText
Dim out As EditText
Dim doit As Button
Dim tr As TextReader
Dim input As InputStream 
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("flay")
'input.initialize         ?????????????????/
tb1.Text = input.IsInitialized  ' shows false of course
tr.Initialize(input)
File.OpenInput(File.DirDefaultExternal,"central.txt")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
File.OpenInput returns an InputStream:
B4X:
    Dim TextReader1 As TextReader
    TextReader1.Initialize(File.OpenInput(File.DirInternal, "central.txt"))
The following code is also fine:
B4X:
    Dim TextReader1 As TextReader
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(File.DirInternal, "central.txt")
    TextReader1.Initialize(InputStream1)

Note that you can also declare the variables locally (if not needed globally).
 

derez

Expert
Licensed User
Longtime User
Thanks, it works. What is the equivalent for EOF (to check if the last read is valid ) ?
 
Last edited:

derez

Expert
Licensed User
Longtime User
:), there is a typo : line = Reader.rReadLine
 
Last edited:

derez

Expert
Licensed User
Longtime User
B4X:
Dim bmp As Bitmap
Dim img As ImageView
Dim cnvs As Canvas
Dim board As Canvas
Dim srect As Rect
Dim drect As Rect
Dim trect As Rect
Dim angle,cx,cy,px,py,x0,y0,a,b As Int
Dim z As Float
Dim zoomval As EditText

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layout1") 
   a = 2
   b = 6
   
   cnvs.Initialize(activity)
   img.Initialize(img)
   board.Initialize(img)
 
Last edited:
Top