Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using jpeg decode / decodeSync

ANSWERED

I read this older blog post, "https://dev.fitbit.com/blog/2018-05-09-introducing-the-imagepicker-and-image-api/"
that mentions the following:

"One approach which tends to work well is to convert the source image into a jpeg with medium compression (40-50), then use the JPEG API on the device to save the jpeg as a txi file. " 

Now I'm trying to convert my existing bundled jpegs (located within `/resources` directory) to `.txi`, however not getting any luck.

Tried the following: 
jpeg.decodeSync('bg-blue-348.jpg', outFileName)

and pointing to the file path: 
jpeg.decodeSync('./resources/assets/bg-blue-348', outFileName)
 
Getting the following error: "Error 0 pjpeg_save_to_file returned Non-zero"
Any help would be appreciated, thank you!
Creator of Pixels on Ridge. Just building fun stuff. Check out some of my Fitbit libraries like fitbit-settings or fitbit-core to help accelerate your development.
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Here's an extract from something of mine (that works):

 

const dataDir = "/private/data/";
jpeg.decodeSync('/mnt/assets/resources/0.jpg', dataDir+'0.txi');

Unfortunately, that error you're getting is rather generic. It could mean unexpected JPEG format (eg, progressive), invalid destination directory, pre-existing destination file (and not using overwrite:true), and more.

 

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
6 REPLIES 6

Try /mnt/assets/resources/ instead of ./resources

 

Might also need file extension.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Unfortunately, still no luck. 

Creator of Pixels on Ridge. Just building fun stuff. Check out some of my Fitbit libraries like fitbit-settings or fitbit-core to help accelerate your development.
Best Answer
0 Votes

Here's an extract from something of mine (that works):

 

const dataDir = "/private/data/";
jpeg.decodeSync('/mnt/assets/resources/0.jpg', dataDir+'0.txi');

Unfortunately, that error you're getting is rather generic. It could mean unexpected JPEG format (eg, progressive), invalid destination directory, pre-existing destination file (and not using overwrite:true), and more.

 

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Ah I see my mistake, I have my images located within resources/assets, so my absolute path was `/mnt/assets/resources/assets/<image>.jpg`, instead I was using `/mnt/resources/assets/<image>.jpg`.

Thanks @Gondwana !

Creator of Pixels on Ridge. Just building fun stuff. Check out some of my Fitbit libraries like fitbit-settings or fitbit-core to help accelerate your development.
Best Answer

👍

Peter McLennan
Gondwana Software
Best Answer
0 Votes

If you use PNG files in your project, they are automatically converted to TXI during the build process.

Best Answer
0 Votes