Hi All,
I've done the search the Forum, read the docs/tuts etc and all seems good until I write the code.
In short a couple of subs capture the Gmap on the screen and save it to Dirinternal. Then it is read from that location for use. Unfortunately the Sub tries to read the file before it is written.
The simple solution is Sleep(100) but different phones operate at different speeds, so waiting for the "save" to finish is the best option.
Below is the code which is pretty well used around B4A. I have tried several variations of Wait For examples without success.
Any help much appreciated.
Regards Roger
[
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
The error log.
			
			I've done the search the Forum, read the docs/tuts etc and all seems good until I write the code.
In short a couple of subs capture the Gmap on the screen and save it to Dirinternal. Then it is read from that location for use. Unfortunately the Sub tries to read the file before it is written.
The simple solution is Sleep(100) but different phones operate at different speeds, so waiting for the "save" to finish is the best option.
Below is the code which is pretty well used around B4A. I have tried several variations of Wait For examples without success.
Any help much appreciated.
Regards Roger
[
			
				B4X:
			
		
		
		Sub BtnSave_Click
    VibBip
   
    Private Obj1, Obj2 As Reflector
    Private args(1) As Object
    Private types(1) As String
    Private Out As OutputStream
    Private Rect1 As Rect
    Private Canvas3 As Canvas
    Private bmp1 As Bitmap
    bmp1.InitializeMutable(Activity.Width,Activity.Height)
    Canvas3.Initialize2(bmp1)
    'No way to take screen shot and show map in one operation
    'SOLUTION: Take picture of Map.  Take screen shot.  Merge both images onto a canvas
   
    'Create folder in DirInternal if required
    If File.Exists(File.Dirinternal&"/ABT/", "") = False Then File.MakeDir(File.Dirinternal&"/ABT/", "")
       
'******Take ScreenShot of Google map, save as map.png
    MapEx.Snapshot(gmap, "gmap")          'Triggers Sub gmap_SnapshotReady  and save map.png
   
'******Take a screenshot and Save as ScrnShotTemp.png
    Obj1.Target = Obj1.GetActivityBA
    Obj1.Target = Obj1.GetField("vg")
    Obj2.Target = Canvas3              
    Obj2.Target = Obj2.GetField("canvas")
    args(0) = Obj2.Target
    types(0) = "android.graphics.Canvas"
    Obj1.RunMethod4("draw", args, types)
    If File.Exists(File.Dirinternal&"/ABT/", "ScrnShotTemp.png") Then File.Delete(File.Dirinternal&"/ABT/", "ScrnShotTemp.png")
    Out = File.OpenOutput(File.Dirinternal&"/ABT/", "ScrnShotTemp.png", False)
    bmp1.WriteToStream(Out, 100, "PNG")
    Out.Close
 
    '********Place Map on Canvas
         Sleep(100)                                                                  'This works but is the crude appoach
    'Wait For gmap_SnapshotReady                                     'This throws an error
   
   
    Rect1.Initialize(0, pnlDispLatLng.Height, 100%x, 100%y)  
    MapCanvas.DrawBitmap(LoadBitmap(File.Dirinternal&"/ABT/", "map.png"), Null, Rect1)          'This is the line that throws the error,  map.png is not found unless Sleep(100) is used.
			
				B4X:
			
		
		
		Sub gmap_SnapshotReady (Bitmap1 As Bitmap)
    Private out As OutputStream
    If File.Exists(File.DirInternal&"/ABT/", "map.png") Then File.Delete(File.DirInternal&"/ABT/", "map.png")
 
    out = File.OpenOutput(File.DirInternal&"/ABT/", "map.png", False)
    Bitmap1.WriteToStream(out, 100, "PNG")
    out.Close
    'wait for (out) Complete(Comp1 As Boolean)                                    'Putting Wait For here leaves the same problem.
End SubThe error log.
main$ResumableSub_BtnSave_Clickresume (java line: 3721)
java.io.FileNotFoundException: /data/user/0/horsetrailer.B4A.AntennaBearingTool/files/ABT/map.png: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:160)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:215)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:516)
at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1342)
at horsetrailer.B4A.AntennaBearingTool.main$ResumableSub_BtnSave_Click.resume(main.java:3721)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at uk.co.martinpearman.b4a.googlemapsextras.GoogleMapsExtras$1.onSnapshotReady(GoogleMapsExtras.java:263)
at com.google.android.gms.maps.zzq.zzc(com.google.android.gmslay-services-maps@@17.0.1:1)
at com.google.android.gms.maps.internal.zzbt.zza(com.google.android.gmslay-services-maps@@17.0.1:2)
			
				Last edited: 
			
		
	
								
								
									
	
		
			
		
	
								
							
							 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		