iOS Question Base64 to Bitmap

Discussion in 'iOS Questions' started by Cornelius Smit, Dec 12, 2018.

  1. Cornelius Smit

    Cornelius Smit Member Licensed User

    Good day I am a bit frustrated as my code work in Android but not in IOS

    I get the following error

    Error occurred on line: 65 (Main)
    Error loading image.
    Stack Trace: (
    CoreFoundation <redacted> + 252
    libobjc.A.dylib objc_exception_throw + 56
    CoreFoundation <redacted> + 0
    Emerald Qld -[B4IBitmap innerInit::] + 352
    Emerald Qld -[B4IBitmap Initialize2:] + 76
    Emerald Qld -[ResumableSub_main_Application_Start resume::] + 5400
    CoreFoundation <redacted> + 144
    CoreFoundation <redacted> + 292
    Emerald Qld +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
    Emerald Qld -[B4IShell runMethod:] + 448
    Emerald Qld -[B4IShell raiseEventImpl:method:args::] + 2164
    Emerald Qld -[B4IShellBI raiseEvent:event:params:] + 1372
    Emerald Qld -[B4IDelegatableResumableSub resume::] + 380
    Emerald Qld -[B4I checkAndRunWaitForEvent:event:params:] + 552
    Emerald Qld -[B4IShellBI raiseEvent:event:params:] + 1228
    Emerald Qld __37-[B4ICommon ReturnFromResumableSub::]_block_invoke + 368
    libdispatch.dylib <redacted> + 24
    libdispatch.dylib <redacted> + 16
    libdispatch.dylib <redacted> + 1068
    CoreFoundation <redacted> + 12
    CoreFoundation <redacted> + 1964
    CoreFoundation CFRunLoopRunSpecific + 436
    GraphicsServices GSEventRunModal + 100
    UIKitCore UIApplicationMain + 212
    Emerald Qld main + 124
    libdyld.dylib <redacted> + 4
    )
    Class (b4i_httpjob) instance released.




    image = "/9j/4AAQSkZJRgABAQEAYABgAAD//gA8Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg\nSlBFRyB2OTApLCBxdWFsaXR5ID0gMTAwCv/bAEMAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\nAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/bAE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Ls2bxf7iti8whFzUIqrhquMq0lUUZVHTw8pUY1KsldctR/\nAqUZcfMo1eaCsoyulvoj839Y+A/jb4PaJ4e8J+N5LC51S20ezknn0m6a+06VipjbyZ5LaxmkjWZZ\nYlaW0t3KRhjEANx+avj98QvHmt+CrT4Xa94hn1bwdp1xEdM0q/igmjtQ0TAWonaM3MtpFbSSRW8U\n1zcRQREQ24it/wByP6BPih8Lz470Wym1FoNQ1vTLZYttraCztboyyIbk28c9zdT26Fwsgie9lXYj\nISzsrD+bv9tX4iaV8Dfih4m8IfFjQp/BFzY6Z/afhRtSa0Fl4q0iQyxWWoaNfQXdxbXMEl1azwXU\niSJJa3KNDcW0U (message truncated)...

    Code:
    wait for (Data.GetEmergincyList)Complete(bList As List)
    If bList.IsInitialized=True Then
        
    For I = 0 To bList.Size-1
          
      
        
    Dim M As Map
        M.Initialize
        M=bList.get(I)
                
    Log(M)
        
    Dim SU As StringUtils
        
    Dim bm1 As Bitmap
                bm1.Initialize(
    File.DirAssets,"emeraldLogo.png")
        
      
      
                
    Dim Base64String As String = m.Get("image")
                
    Dim FileBytes() As Byte
                
    Dim bm As Bitmap
                
    If Base64String.Length > 4 Then
                    FileBytes=SU.DecodeBase64(Base64String.Trim)
                    
    Dim Inputstream1 As InputStream
                    Inputstream1.InitializeFromBytesArray(FileBytes,
    0,FileBytes.Length)
                    bm.Initialize2(Inputstream1)  
    '<-----ERROR ON THIS LINE
                  
                  
                  
                  
                    Inputstream1.Close
                    Sleep(
    100)
                
    Else
     
    Last edited: Dec 12, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    Please upload a text file with the base64 string.
     
  3. Cornelius Smit

    Cornelius Smit Member Licensed User

    it is a blob (image) in a MySQL database that I convert to base64 in the select statement not sure how to get the file from the mobile device. The thing is I use the same blob and same SQL statement from the same web service and it is working
     
    Last edited: Dec 12, 2018
  4. Cornelius Smit

    Cornelius Smit Member Licensed User

    Another thing I noticed (think this must be a new thread )just want to mention it is that if I use xcustomview the app display a blank screen and it is then impossible to recover by removing the library (working 100% in B4A) as I need to create a new project then
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    True.

    You can save it in File.DirDocuments and enable file sharing: https://www.b4x.com/android/forum/threads/files-and-folders.46137/#content
     
  6. Cornelius Smit

    Cornelius Smit Member Licensed User

    I have added this line
    Code:
    Dim M As Map
        M.Initialize
        M=bList.get(I)
                
    Log(M)
        
     
    File.WriteMap(File.DirDocuments,"imagemap",M) '<------------------------------------------------------------error moved here
    and now the error has moved to this line
    if I break the code and hover on the map os list for that matter the program stop and give me an error
     
    Last edited: Dec 14, 2018
  7. Erel

    Erel Administrator Staff Member Licensed User

    We cannot help you with the information you provide.

    What is MyMap? Which error? If MyMap is not a string then your code is wrong and you should use B4XSerializator instead.

    Code:
    Dim M As Map
        M.Initialize
        M=bList.get(I)
    This is a mistake. Never initialize an object and then assign a new object to the same variable.

    All these points are covered in the video tutorials.
     
  8. Cornelius Smit

    Cornelius Smit Member Licensed User

    Sorry my mistake I renamed it, it should b only M And the error is still on this line the more If I stop the code and hover my cursor the app stop with an error even if I add try/catch it does not even go to the error handling routine it stop dead in its tracks I start to think it could be a compile or IDE problem.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but I don't understand anything. Each thread should focus on one specific question or issue.
     
  10. Cornelius Smit

    Cornelius Smit Member Licensed User

    Can I send you a video (Screen Record)?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    A video will not help. I recommend you to start a new thread and explain a single issue that you encounter.
     
  12. Cornelius Smit

    Cornelius Smit Member Licensed User

    OK Found the Issue one of my fields had a null value (empty) when I created the list from my query to the database.however in B4A it inserts a "null" string if the field is empty but in b4I it crashes. That is the reason it was working in Android and not in IOS

    using this to create my list

    Dim job As HttpJob
    Dim ListResults As List
    job.Initialize("job",Me)
    job.PostString(Global.DataServer, Query)
    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then
    Dim parser As JSONParser
    Log(job.GetString)
    parser.Initialize(job.GetString)
    ListResults = parser.NextArray 'returns a list with maps
    If ListResults.Size=0 Then
    If job.IsInitialized Then
    job.Release
    End If
    hud.ProgressDialogHide
    Return ListResults
    Else
     
    Last edited: Dec 14, 2018
  13. Cornelius Smit

    Cornelius Smit Member Licensed User

    Hi Erel
    I found the issue and explained it in the next post.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice