B4J Question Save Image make application run slowly.

supriono

Member
Licensed User
Longtime User
hello friend...
i have same trouble with my code...
i want to save image form 4 IP camera and save image to drive C:
for this case i am use webview.

this is my code :
B4X:
Sub timeout_Tick  ' if tick timer1 on (open kamera 1)
    timer1.Enabled=True
    timeout.Enabled=False
End Sub

Sub timer1_Tick
    webview1.LoadUrl("http://192.168.0.11/CH1.jpg?") ' open page IP camera 1
    timer1.Enabled=False 'timer1 off
End Sub

Sub WebView1_PageFinished (URL As String)
    label1.Text="1"
    If counter1 >0 Then: counter1 =counter1 -1
    Else :counter1=10000 ' get 10.000 frame image
    End If
    save (1,counter1 )
    webview2.LoadUrl("http://192.168.0.12/CH2.jpg?")' open page IP camera 2
    timeout.Enabled=True ' timer timeout is on
End Sub
Sub WebView2_PageFinished (URL As String)
    label1.Text="2"
    If counter2 >0 Then: counter2=counter2 -1
    Else :counter2=10000
    End If
    save (2,counter2 )
    webview3.LoadUrl("http://192.168.0.13/CH3.jpg?")' open page IP camera 3
    timeout.Enabled=True' timer timeout is on
End Sub
Sub WebView3_PageFinished (URL As String)
    label1.Text="3"
    If counter3 >0 Then: counter3 =counter3 -1
    Else :counter3=10000
    End If
    save (3,counter3 )
    webview4.LoadUrl("http://192.168.0.14/CH4.jpg?")' open page IP camera 4
    timeout.Enabled=True' timer timeout is on
End Sub
Sub WebView4_PageFinished (URL As String)
    label1.Text="4"
    If counter3 >0 Then: counter3 =counter3 -1
    Else :counter1=10000
    End If
    save (4,counter4 )
    webview1.LoadUrl("http://192.168.0.11/CH1.jpg?")' open page IP camera 1
    timeout.Enabled=True' timer timeout is on
End Sub

Sub save (number_kamera As Int,number_image As String)
    If flag_record=True Then
        Select number_kamera:
        Case 1 :  Dim out As OutputStream = File.OpenOutput("C:\KAMERA 1", number_image&".png", False):webview1.Snapshot.WriteToStream(out)
        Case 2 :  Dim out As OutputStream = File.OpenOutput("C:\KAMERA 2", number_image&".png", False):webview2.Snapshot.WriteToStream(out)
        Case 3 :  Dim out As OutputStream = File.OpenOutput("C:\KAMERA 3", number_image&".png", False):webview3.Snapshot.WriteToStream(out)
        Case 4 :  Dim out As OutputStream = File.OpenOutput("C:\KAMERA 4", number_image&".png", False):webview4.Snapshot.WriteToStream(out)
        End Select   
        out.Close
    End If
End Sub

application fine if not save/record image so drive C: bud when i record image, aplication run very slowly...may be save 2 second/image.
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Isn't it better to download these images using httputils and at JobDone event write bitmap to the folder ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I think the folder "C:\KAMERA 1" is not available on your Device runng the Android. Android does not have Drive-Letters ;-)
Forget my post; i was stupid... i didn´t realize that i´m writing in B4J-forum. Sorry
 
Upvote 0

supriono

Member
Licensed User
Longtime User
last time i am chage my code with jobdone(sugestion from somed) bud i have this error

Program started.
save OK
save OK
save OK
httpjob._getbitmap (java line: 147)
java.io.FileNotFoundException: C:\Users\MEKARO~1\AppData\Local\Temp\6 (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:199)
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize(ImageViewWrapper.java:81)
at anywheresoftware.b4j.objects.JFX.LoadImage(JFX.java:98)
at b4j.example.httpjob._getbitmap(httpjob.java:147)
at b4j.example.main._jobdone(main.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:440)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:420)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:494)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)


B4X:
timer1.Initialize("timer1",200)
Sub JobDone(job As HttpJob)
   If job.Success Then
        counter1=counter1-1
     ip1.SetImage(job.GetBitmap)
     Dim out As OutputStream = File.OpenOutput("C:\KAMERA 1", counter1&".png", False)
     ip1.Snapshot.WriteToStream(out)
    ' File.Copy2(job.GetInputStream, out)
     out.Close '<------ very important
     Log("save OK")
   Else
     Log("Error: " & job.ErrorMessage)
   End If
   job.Release
End Sub

Sub timer1_Tick
    IPCAM.Download("http://192.168.0.11/CH1.jpg?")
End Sub

i thing error java.io.FileNotFoundException: C:\Users\MEKARO~1\AppData\Local\Temp\6 (The system cannot find the file specified)
is sistem can't finis download image..
my be erel can help my trouble
 
Upvote 0
Top