LoadJpegSizeOnly error

boten

Active Member
Licensed User
Longtime User
This is part of the app that take a picture using ACL and trying to read the pic's dimension with JPEG.

B4X:
Sub Cam_PictureTaken(Data() As Byte)
Save_Temp_Pic(Data)
Process_Temp_Pic
End Sub

Sub Save_Temp_Pic(Data() As Byte)
If File.Exists(AppPath,"tmp1.jpg") Then File.Delete(AppPath,"tmp1.jpg")
'--- Write picture
Dim objStream As OutputStream   
objStream = File.OpenOutput(AppPath,"tmp1.jpg", False)
objStream.WriteBytes(Data, 0, Data.Length)
objStream.Close
End Sub

Sub Process_Temp_Pic
Dim input As InputStream
input = File.OpenInput(AppPath,"tmp1.jpg")
jpg.LoadJpegSizeOnly(input)
Msgbox(jpg.JpegWidth & "x" & jpg.JpegHeight,"tmp1 size")
input.Close
End Sub

The picture is taken, there is a file tmp1.jpg in the specified directory, but jpg.LoadJpegSizeOnly gives the error:
(jpg is DIMed in Sub Globals: Dim jpg As Jpeg)

B4X:
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
main_process_temp_pic (B4A line: 87)
jpg.LoadJpegSizeOnly(input)

java.lang.NullPointerException
   at anywheresoftware.b4a.agraham.jpeg.Jpeg.LoadJpegSizeOnly(Jpeg.java:130)
   at boten.btst.main._process_temp_pic(main.java:464)
   at boten.btst.main._cam_picturetaken(main.java:323)
   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.raiseEvent2(BA.java:158)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
   at xvs.ACL.ACL$4.onPictureTaken(ACL.java:239)
   at android.hardware.Camera$EventHandler.handleMessage(Camera.java:734)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4745)
   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:786)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
** Activity (main) Pause, UserClosed = true **
 

boten

Active Member
Licensed User
Longtime User
Silly me, sometimes the obvious is ignored.

i had now: jpg.Initialize("") in Activity_Create.

But now the error is:
B4X:
** Activity (main) Create, isFirst = true **

** Activity (main) Resume **

main_process_temp_pic (B4A line: 88)

jpg.LoadJpegSizeOnly(input)

java.lang.Exception: Jpeg error: Frame format error [Lf!=count]
   at anywheresoftware.b4a.agraham.jpeg.Jpeg$JPEGDecoder.error(Jpeg.java:511)
   at anywheresoftware.b4a.agraham.jpeg.Jpeg$JPEGDecoder.access$3(Jpeg.java:509)
   at anywheresoftware.b4a.agraham.jpeg.Jpeg$JPEGDecoder$FrameHeader.get(Jpeg.java:589)
   at anywheresoftware.b4a.agraham.jpeg.Jpeg$JPEGDecoder.decode(Jpeg.java:1457)
   at anywheresoftware.b4a.agraham.jpeg.Jpeg.LoadJpegSizeOnly(Jpeg.java:130)
   at boten.btst.main._process_temp_pic(main.java:470)
   at boten.btst.main._cam_picturetaken(main.java:326)
   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.raiseEvent2(BA.java:158)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
   at xvs.ACL.ACL$4.onPictureTaken(ACL.java:239)
   at android.hardware.Camera$EventHandler.handleMessage(Camera.java:734)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4745)
   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:786)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: Jpeg error: Frame format error [Lf!=count]
 
Upvote 0

boten

Active Member
Licensed User
Longtime User
I ran it twice:

Once on SGS Froyo - Works OK

Second on ASUS TF300 JellyBean - Got the error.

Same prog, no changes. File is viewable in Gallery both devices.
 
Upvote 0
Top