Android Question Take Photo in B4XPages

netsistemas

Active Member
Licensed User
Longtime User
In my proyect B4XPages i need take photo with android

i go to include a condicionarl compiler clausele (#if b4a) for lunck this ONLY in Android, but...

The code to take photo (copy paster from other proyect), can insert in P4XPages general, or a need lunch as new activity?

is there any form/thecnic for do this in b4xpages without new activity?
 

netsistemas

Active Member
Licensed User
Longtime User
thanks, but is more complicate my proyect.
I have an activity that take photo and EXTRACT a BarCode from imagen. This proyect are based in a solution in this forum for detect barcode.
The idea is to have an activity, taking mini-photo and decode image to extract the string in barcode image.
B4X:
Dim s As String = nativeMe.RunMethod("decodeQRImage", Array(mbm))

so a need my code in: other activity? i think that is necesary, but may be i can put a panel in page and take photo, but show nothing in page.
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Attach sample with second page, but no run.
Reference used:
- Audio (1.71
- B4XPages (1.06)
- Camera2(1.11)
- Core (9.9)
-RunTimePermision (1.12)

(if something copy/past code, remembar include :

#AdditionalJar: core-3.3.2.jar in main #Region proyect attributes

why no run?
 

Attachments

  • DemoCBarrasxFoto.zip
    21.9 KB · Views: 179
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Yes, that is the problem:
if in the code, remove (or comment) the
'cam.Initialize(pnlCamera)
the layout are visible, but if include this importan line, is like other panel catch this other panel and are not visible nothing.

B4X:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root

    nativeMe.InitializeContext
    t.Initialize("t", 300)
    tLine.Initialize("tLine",50)
    
    
    If Nombre_FotoBase = "" Then
        VideoFileName =  "LibreVideo_" &  "modB4A.GetFileNameUnico" & ".mp4"
    Else
        VideoFileName =  Nombre_FotoBase & "_" & "modB4A.GetFileNameUnico"  & ".mp4"
    End If
    Root.LoadLayout("Layout_Foto")
    Root.LoadLayout("LayoutStillPicture")
    'cam.Initialize(pnlCamera)   '<------------------------------------ important line (i think)'
    
    'Log(cam.SupportedHardwareLevel)
    buttons = Array(btnScene, btnAutoExposure, btnEffects, btnFocus, btnMode)
    'SetState(False, False, VideoMode)

    
End Sub
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Since you're using it in a class (the B4xPages) you should call nativeMe = Me instead of nativeMe.InitializeContext.
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
thanks,
mybe this line are bud, but this is not the main problem because this object only are used for get 'decodeQRImage'
Dim s As String = nativeMe.RunMethod("decodeQRImage", Array(mbm))

The problem,i think, is that no camara are activated in pnlCamara : cam.Initialize( pnlCamera)

Maybe de solution is get other mainpanel in b4xpages and set to cam.initialize
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Finally.
I insert detect barcode in other activiy.
I do not the cause, but in full screen and using camera2 (version 1.11) and decodeQRImage is more fast that (the problem, i think is not decodeQrImage function vs frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null) thecnic. Is full screen. Me opinion. )



about my code, I have not been able to do to make it work
but, is very important put this code in sub Initialize, not in b4xpage_created


REMEMBER insert #AdditionalJar: core-3.3.2.jar in Regoin Proyect Attributes

B4X:
Public Sub Initialize
            nativeMe= Me

End Sub

Addional:
For use decodeQrImagen java inline methot i use this other code
B4X:
public String hola(){
    return "hola";
}

#End If


Public Sub Initialize
            nativeMe= Me

End Sub
Private Sub Camera1_Preview (data() As Byte)
Dim s As String
   
       
            Dim jpeg() As Byte = camEx.PreviewImageToJpeg(data, 70)
           
            Dim bmp As Bitmap
            Dim ins As InputStream
 
            ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
            bmp.Initialize2(ins)
            ins.Close
        bmp  = bmp.Rotate(90)


            s = nativeMe.RunMethod("decodeQRImage",Array(bmp))
            If s <> "" Then
               
                FoundBarcode(s)
            End If
           
end sub            

#if Java




import com.google.zxing.MultiFormatWriter;
import android.graphics.Bitmap;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.qrcode.decoder.Version;

import android.graphics.BitmapFactory;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.MultiFormatReader;


import android.util.Base64;
import java.io.ByteArrayOutputStream;

public String decodeQRImage(Bitmap bMap) {

    String decoded = "";

    int[] intArray = new int[bMap.getWidth() * bMap.getHeight()];
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(),
            bMap.getHeight());
    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(),
            bMap.getHeight(), intArray);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

   
    Reader reader = new MultiFormatReader();
    try {
   
        Result result = reader.decode(bitmap);
        decoded = result.getText();
        BA.Log("HERE");
       

    } catch (NotFoundException e) {
         BA.Log("NotFoundException: " + e.getMessage());
    } catch (ChecksumException e) {
        BA.Log("ChecksumException: " + e.getMessage());
    } catch (FormatException e) {
        BA.Log("FormatException: " + e.getMessage());
    }
    return decoded;
}

#End If
 
Upvote 0
Top