Android Question SMB1.DownloadFile2 sample

Tayfur

Well-Known Member
Licensed User
Longtime User
Hi;
So, I have some problem. I want open photo from LAN PC

first way is ....
SMB1.DownloadFile("smb://192.168.1.222/KALITE_RAPOR/", "logo.jpg", File.DirRootExternal,"logo.jpg")
------its work. No problem

But this way record the file on phone.
this code 1. step (save on phone) 2.step (open photo on phone). :(

I want to use ram/stream etc. I dont want save on phone. How I can it?


I have problem lines in "SMB1_DownloadCompleted".


(sorry I am new...)
B4X:
'************IT S WORK LINE*****************
'SMB1.DownloadFile2("smb://192.168.1.222/KALITE_RAPOR/", "logo.jpg",sout,True)
'*******************************
Sub SMB1_DownloadCompleted (Url As String, RemoteFile As String, Success As Boolean)
  If Not(Success) Then
      ToastMessageShow("Download failed : " & LastException,False)
  Else
        ToastMessageShow("Download : " & RemoteFile & " downloaded",False)
        ToastMessageShow(File.DirRootExternal & "logo.jpg", False)
        'ImageView1.Bitmap = LoadBitmap(File.DirRootExternal, "logo.jpg")
        'Dim photo As Bitmap
        'ImageView1.Initialize("")
        'photo.Initialize3(ImageView1.Bitmap)
        'sout=siin
        'Dim Bitmap1 As ImageView' Image
        'photo.Initialize2(siin)' (photo)
        'photo.WriteToStream(sout, 10, "JPEG")
        'ImageView1.WriteToStream( sout, 100, "JPEG")' OutputStream1, 10, "JPEG")
        'ImageView1.Bitmap= Bitmap.WriteToStream(siin, 10, "JPEG")
    End If   
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I actually recommend you to use a temporary file. It will be simpler and the performance will be the same.

How I can load from outputstream to imagewiew?
B4X:
Dim data() As Byte = OutputStream.ToBytesArray
Dim in As InputStream
in.InitializeFromBytesArray(data, 0, data.Length)
Dim bmp As Bitmap
bmp.Initialize2(in)
in.Close
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
thak you for reply.
it s work . But; its dont work big files. (out of memory problem and program broke)
I tyr a lot time diffrenet size pictures.
and I have some results. (Res 96dpi / 24bit)
(Picture size = width x heigth <8.932.000 then it s work)
(Picture size =width x heigth >8.932.000 then it DONT work)
Why not working. I dont undurstant it.
How can i do wrong ? :)



B4X:
Installing file.
PackageAdded: package:anywheresoftware.b4a.objects.smb
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*****************
*****************
logo.jpg
false
01/13/2014
smb://192.168.1.222/TEKNIK_RESIM/TRELLEBORG/
1320365
main_smb1_downloadcompleted (B4A line: 95)
bmp.Initialize2(siin)
java.lang.OutOfMemoryError
    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:652)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:724)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:519)
    at anywheresoftware.b4a.objects.smb.main._smb1_downloadcompleted(main.java:517)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA$3.run(BA.java:312)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4921)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
    at dalvik.system.NativeStart.main(Native Method)

this is my final code...
B4X:
Dim data() As Byte = sout.ToBytesArray ' sout =>  OutputStream
            siin.InitializeFromBytesArray(data, 0, data.Length) ' siin =>  inputStream
            bmp.Initialize2(siin)
            siin.Close
            ImageView1.Bitmap=bmp
 
Last edited:
Upvote 0
Top