Android Question Panel didn't show image

Xandoca

Active Member
Licensed User
Longtime User
Hi,

My app had a activty that has a panel with camera inside. User click in a button in take picture. I want to show that picture inside the same panel. (turn off camera and shows the picture). It's not working.
If I leave my app like pressing home button and the back to the app the picture shows.
Below the code ....
B4X:
Sub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = maxIDTabela("ODS_REGISTROS") & ".jpg"
    Dim dir As String = File.DirRootExternal & "/AP-Memoria/Fotos"
   
    camEx.SavePictureToFile(Data, dir, filename)
    'camEx.StartPreview 'restart preview
    camEx.CloseNow
   
    'send a broadcast intent to the media scanner to force it to scan the saved file.
    Dim Phone As Phone
    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
        "file://" & File.Combine(dir, filename))
    Phone.SendBroadcastIntent(i)
    ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
   
       
   
        Dim bd As BitmapDrawable
        bd.Initialize(LoadBitmap(Main.DBFileDir & "/Fotos",maxIDTabela("ODS_REGISTROS") & ".jpg"))
        bd.Gravity = Gravity.Fill
        pnlFoto.Background = bd
        lblTirarFoto.Text = "Nova Foto"
End Sub
 

Xandoca

Active Member
Licensed User
Longtime User
You should call camEx.Close instead of camEx.CloseNow.

Is pnlFoto the same panel that is used for the preview frames?
Tks.
I couldn't find camEx.Close method in CameraExClass (lib Camera version 2.20).

It's the same panel.
 
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
I've meant CamEx.Release.

You should use a different panel to show the image.
Same problem. Panel shows a black screen.
After I pressed home button and then return the new panel shows the picture.
B4X:
    Dim filename As String = maxIDTabela("ODS_REGISTROS") & ".jpg"
    Dim dir As String = File.DirRootExternal & "/AP-Memoria/Fotos"
   
    camEx.SavePictureToFile(Data, dir, filename)
    'camEx.StartPreview 'restart preview
    'camEx.CloseNow
    camEx.Release
   
    'send a broadcast intent to the media scanner to force it to scan the saved file.
    Dim Phone As Phone
    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
        "file://" & File.Combine(dir, filename))
    Phone.SendBroadcastIntent(i)
    ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
   
        'tratamento depois que tirar a foto
       
        Dim bd As BitmapDrawable
        bd.Initialize(LoadBitmap(Main.DBFileDir & "/Fotos",maxIDTabela("ODS_REGISTROS") & ".jpg"))
        bd.Gravity = Gravity.Fill
        pnlFotoGravada.Background = bd
        pnlFotoGravada.BringToFront
        lblTirarFoto.Text = "Nova Foto"
 
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
The database file is missing. Note that it is better to let the program crash than to catch the error. It made it more difficult to understand why it crashes later.
Attached the database file.
Tks.
 

Attachments

  • ap-memoria.zip
    1.3 KB · Views: 157
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
I've tested it here and the image appears after the picture is taken.

Try to add DoEvents and pnlFotoGravada.Invalidate.
Tks.
I've tested it with Galaxy Tab 2 and it works. But it doesn't work with xperia mini and RAZR D3. Even using DoEvents and pnlFotoGravada.Invalidate.
Thank you very much for your time.
 
Upvote 0
Top