jpeg error. format error.

MarkoMylo

Member
Licensed User
Longtime User
check this and help.

Sub Globals
Dim iv1 As ImageView
Dim bmp As Bitmap
Dim jpg As Jpeg
Dim In As InputStream
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim Canvas1 As Canvas
Dim DestRect As Rect
Dim SrcRect As Rect
Activity.LoadLayout("320p")
jpg.Initialize("jpg")
In = File.OpenInput(File.DirAssets, "z.jpg")
bmp = jpg.LoadJpegArea(In,0,0,140,140)
iv1.SetBackgroundImage(bmp)

End Sub

On mobile screen i get error An error occured in sub main activity create in line .... bmp = jpg.LoadJpegArea(In,0,0,140,140)
On PC screen I get error JPEG ERROR. FORMAT ERROR. PARSER.DECODE

:signOops:

Cant load one area of picture previously loaded in FILES. Same error when i use DirRootExternal and when i put that jpeg file on sdcard.
 

MarkoMylo

Member
Licensed User
Longtime User
Please use [ code ] [ /code ] tags (without spaces) when posting code.

I guess that jpg.LoadJpegArea requires random access to the file. File.DirAssets is a virtual folder so it fails. Copying to any other location will work. If it doesn't then please upload your project (File - Export as zip).

B4X:
sub Globals
Dim jpg As Jpeg
Dim In As InputStream
end sub

Sub Activity_Create(FirstTime As Boolean)
Dim Canvas1 As Canvas
Dim DestRect As Rect
Dim SrcRect As Rect

Label1.Initialize("")    
    Label1.TextSize= 30

Activity.LoadLayout("320p")
jpg.Initialize("jpg")
In = File.OpenInput(File.DirAssets, "z.jpg")    

bmp = jpg.LoadJpegArea(In,0,0,140,140)
iv1.SetBackgroundImage(bmp)
end sub


there is an error: JPEG ERROR. FORMAT ERROR. PARSER DECODE.
sth like that
 
Upvote 0

MarkoMylo

Member
Licensed User
Longtime User
Files stored in File.DirAssets are actually located inside the APK file. The Jpeg library requires random access so it cannot work with such files. You will need to copy it to another folder and then open it.

NO, when i put DirRootExternal, same thing,
only i've noticed is when i do not save that Z.jpg file on sd card there is one error : file not found, and that is ok,

but when i save Z.jpg there is error again "format error,parser decode", so conclusion is, program can find this file but i dont know why this error appears
 
Upvote 0
Top