I am trying to return the scanned bitmap image from the Zxing library to the B4A project but I am getting the following error:
java.lang.Exception: Sub myzx_result signature does not match expected signature.
I have added the following code (in red) to method handleDecode in class CaptureActivity:
public void handleDecode(Result obj, Bitmap barcode) {
inactivityTimer.onActivity();
viewfinderView.drawResultBitmap(barcode);
Log.i("B4A", obj.getBarcodeFormat().toString()+":"+obj.getText()+"###"+b4aZXingLib.en+"_result");
Intent data=new Intent();
data.putExtra("atype", obj.getBarcodeFormat().toString());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
barcode.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
data.putExtra("image",byteArray);
Changed the following in class b4aZXingLib
//@Events(values={"result(atype as String,Value as String)"})
@Events(values={"result(atype as String,Value as String, image as Bitmap)","noscan(atype as String, Value as String, image as Bitmap)"})
Also added the following code to method ResultArrived in class b4aZXingLib (in red):
public void BeginScan(BA ba,String EventName) {
myba=ba;
en=EventName.toLowerCase();
Intent izx;
izx=new Intent(BA.applicationContext, CaptureActivity.class);
ion=new IOnActivityResult()
{
@override
public void ResultArrived(int arg0, Intent arg1) {
String atype;
String Value;
Bitmap image; //added
atype = "";
Value = "";
image = null; //added
if (arg0==-1){
atype=arg1.getStringExtra("atype");
Value=arg1.getStringExtra("value");
byte[] byteArray = arg1.getByteArrayExtra("image");
image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
myba.raiseEvent2(null, false, en+"_result", true, new Object[]{atype,Value,image}); //added image
} else {
atype = "Null";
Value = "Null";
image = null;
myba.raiseEvent2(null, false, en+"_noscan", true, new Object[]{atype,Value,image}); //added image
}
}
};
ba.startActivityForResult(ion, izx);
}
The B4A sub is as follows:
I return a String, String, and Bitmap (in that order) from the library. Why the "signature does not match expected signature" error? The scanner scans but does not fire "Sub myzx_result" and then generates the error.
Some pointers/assistance will be very much appreciated.
java.lang.Exception: Sub myzx_result signature does not match expected signature.
I have added the following code (in red) to method handleDecode in class CaptureActivity:
public void handleDecode(Result obj, Bitmap barcode) {
inactivityTimer.onActivity();
viewfinderView.drawResultBitmap(barcode);
Log.i("B4A", obj.getBarcodeFormat().toString()+":"+obj.getText()+"###"+b4aZXingLib.en+"_result");
Intent data=new Intent();
data.putExtra("atype", obj.getBarcodeFormat().toString());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
barcode.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
data.putExtra("image",byteArray);
Changed the following in class b4aZXingLib
//@Events(values={"result(atype as String,Value as String)"})
@Events(values={"result(atype as String,Value as String, image as Bitmap)","noscan(atype as String, Value as String, image as Bitmap)"})
Also added the following code to method ResultArrived in class b4aZXingLib (in red):
public void BeginScan(BA ba,String EventName) {
myba=ba;
en=EventName.toLowerCase();
Intent izx;
izx=new Intent(BA.applicationContext, CaptureActivity.class);
ion=new IOnActivityResult()
{
@override
public void ResultArrived(int arg0, Intent arg1) {
String atype;
String Value;
Bitmap image; //added
atype = "";
Value = "";
image = null; //added
if (arg0==-1){
atype=arg1.getStringExtra("atype");
Value=arg1.getStringExtra("value");
byte[] byteArray = arg1.getByteArrayExtra("image");
image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
myba.raiseEvent2(null, false, en+"_result", true, new Object[]{atype,Value,image}); //added image
} else {
atype = "Null";
Value = "Null";
image = null;
myba.raiseEvent2(null, false, en+"_noscan", true, new Object[]{atype,Value,image}); //added image
}
}
};
ba.startActivityForResult(ion, izx);
}
The B4A sub is as follows:
B4X:
Sub myzx_result(atype As String, Value As String, image As Bitmap)
ImageView1.Bitmap = image
Log("type:" & atype & "Value:" & Value)
Msgbox(Value,"type:" & atype)
End Sub
I return a String, String, and Bitmap (in that order) from the library. Why the "signature does not match expected signature" error? The scanner scans but does not fire "Sub myzx_result" and then generates the error.
Some pointers/assistance will be very much appreciated.
Last edited: