Android Question screenshot and dirInternal

settedicinque

Member
Licensed User
Longtime User
Hi all, I need your help. Is it possible let the users make a screenshot and save it in dirInternal? I tried using the code in the beginner's guide but it didin't work. I don't have any error messages, but on the phone doesn't appear any screenshot.
 

settedicinque

Member
Licensed User
Longtime User
Private Obj1, Obj2 As Reflector
Private bmp As Bitmap
Private c As Canvas
Private now As Long
Private dt As String
DateTime.DateFormat = "yyMMddHHmmss"
now = DateTime.now
dt = DateTime.Date(now) ' e.g.: "110812150355" is Aug.12, 2011, 3:03:55 p.m.
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = ScrollView1.Panel
bmp.InitializeMutable(Activity.Width, Activity.Height)
c.Initialize2(bmp)
Private args(1) As Object
Private types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Private Out As OutputStream
Out = File.OpenOutput(File.DirInternal, dt & ".png", False)
bmp.WriteToStream(Out, 100, "PNG")
Out.Close


this is the code.Thank you
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
please use code tags when posting, it makes things easier to read.

I am using almost the same code, the only difference is in one line (which I don't understand anyway!)

B4X:
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = Obj1.GetField("vg")
 
Upvote 0

settedicinque

Member
Licensed User
Longtime User
Erel, nothing happens. I've tried with scrollview, with panel, with activity, but nothing happens. No error message, but no screenshot
 
Upvote 0

settedicinque

Member
Licensed User
Longtime User
Thank you Luca. In the original program I didn't forget to initialize the canvas and the cod didin't work anyway. However, I think I have understood now. Instead of dirinternal I must write dirRootExternal, to save the picture on my phone.
This new code works for me.

Luca volevo fare in modo che gli utenti salvassero gli oggetti che modificavano nel panel, e poichè è scorrevole un semplice screenshot non va bene. Anche questo codice comunque non è perfetto perchè la foto è salvata in posti strani, ancora devo capire come fare per far salvare il file dove uno vuole.
 

Attachments

  • screenshot3.zip
    8.2 KB · Views: 132
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Luca volevo fare in modo che gli utenti salvassero gli oggetti che modificavano nel panel, e poichè è scorrevole un semplice screenshot non va bene. Anche questo codice comunque non è perfetto perchè la foto è salvata in posti strani, ancora devo capire come fare per far salvare il file dove uno vuole.

Non so bene cosa vuoi ottenere, chiaramente, ma probabilmente ti conviene usare una CustomListView, molto più semplice da gestire.
A meno che non ci siano problemi di versioni di Android, l'immagine puoi salvarla in tre posti: DirDefaultExternal (consigliata), DirInternal, DirRootExternal.
Allego un esempio che salva soltanto il contenuto di una ScrollView (cosa che si può fare anche con la CustomListView, essendo questa una ScrollView).

I don't know exactly what you want to achieve, of course, but probably you should use a CustomListView, much easier to handle.
Unless there are problems of Android versions, you can save the image to: DirDefaultExternal (recommended), DirInternal, DirRootExternal.
I attach an example that saves only the contents of a ScrollView (which can also be done with the CustomListView, which is a ScrollView).
 

Attachments

  • screenshot4.zip
    9 KB · Views: 137
Upvote 0
Top